1- import moment from 'moment'
1+ import moment from 'moment-timezone '
22import {
33 PRICE_API_DATE_FORMAT ,
44 RESPONSE_MESSAGES ,
@@ -47,11 +47,10 @@ function isNetworkValid (slug: NetworkTickersType): boolean {
4747 return Object . values ( NETWORK_TICKERS ) . includes ( slug )
4848}
4949
50- const getPaybuttonTransactionsFileData = ( transaction : TransactionWithAddressAndPrices , currency : SupportedQuotesType ) : TransactionFileData => {
50+ const getPaybuttonTransactionsFileData = ( transaction : TransactionWithAddressAndPrices , currency : SupportedQuotesType , timezone : string ) : TransactionFileData => {
5151 const { amount, hash, address, timestamp } = transaction
5252 const value = getTransactionValueInCurrency ( transaction , currency )
53- const date = moment ( timestamp * 1000 )
54-
53+ const date = moment . tz ( timestamp * 1000 , timezone )
5554 const rate = value / amount . toNumber ( )
5655
5756 return {
@@ -106,6 +105,7 @@ const downloadPaybuttonTransactionsFile = async (
106105 res : NextApiResponse ,
107106 paybutton : PaybuttonWithAddresses ,
108107 currency : SupportedQuotesType ,
108+ timezone : string ,
109109 networkTicker ?: NetworkTickersType ) : Promise < void > => {
110110 let networkIdArray = Object . values ( NETWORK_IDS )
111111 if ( networkTicker !== undefined ) {
@@ -117,7 +117,7 @@ const downloadPaybuttonTransactionsFile = async (
117117 const sortedTransactions = await sortTransactionsByNetworkId ( transactions )
118118
119119 const mappedTransactionsData = sortedTransactions . map ( tx => {
120- const data = getPaybuttonTransactionsFileData ( tx , currency )
120+ const data = getPaybuttonTransactionsFileData ( tx , currency , timezone )
121121 return formatPaybuttonTransactionsFileData ( data )
122122 } )
123123 const headers = Object . keys ( PAYBUTTON_TRANSACTIONS_FILE_HEADERS )
@@ -160,9 +160,12 @@ export default async (req: any, res: any): Promise<void> => {
160160 if ( paybutton . providerUserId !== userId ) {
161161 throw new Error ( RESPONSE_MESSAGES . RESOURCE_DOES_NOT_BELONG_TO_USER_400 . message )
162162 }
163+ const userReqTimezone = req . headers . timezone as string
164+ const userPreferredTimezone = user ?. preferredTimezone
165+ const timezone = userPreferredTimezone !== '' ? userPreferredTimezone : userReqTimezone
163166
164167 res . setHeader ( 'Content-Type' , 'text/csv' )
165- await downloadPaybuttonTransactionsFile ( res , paybutton , quoteSlug , networkTicker )
168+ await downloadPaybuttonTransactionsFile ( res , paybutton , quoteSlug , timezone , networkTicker )
166169 } catch ( error : any ) {
167170 switch ( error . message ) {
168171 case RESPONSE_MESSAGES . PAYBUTTON_ID_NOT_PROVIDED_400 . message :
0 commit comments