From cdc7e69598415bf41b8734f541ff9c4c4b6634bb Mon Sep 17 00:00:00 2001 From: Josepablo C Date: Tue, 29 Jul 2025 22:08:41 -0600 Subject: [PATCH] fix: Set TZ to UTC --- v1/package.json | 1 + v1/src/apps/private/loads/services.js | 1 + v1/src/config/apiConfig.json | 2 +- v1/src/index.js | 2 ++ v1/src/lib/Misc.js | 17 ++++++++++------- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/v1/package.json b/v1/package.json index 25e270a..54e912a 100644 --- a/v1/package.json +++ b/v1/package.json @@ -36,6 +36,7 @@ "jsonwebtoken": "^9.0.2", "knex": "^2.5.1", "minio": "^8.0.1", + "moment": "^2.30.1", "mongodb-core": "^3.2.7", "mongoose": "^7.5.4", "morgan": "^1.10.0", diff --git a/v1/src/apps/private/loads/services.js b/v1/src/apps/private/loads/services.js index 553ebb8..9d9b0f5 100644 --- a/v1/src/apps/private/loads/services.js +++ b/v1/src/apps/private/loads/services.js @@ -313,6 +313,7 @@ function normalizeDatesFromData( data ){ ]; for( const item of fields2normalize ){ if( Object.hasOwn( data, item ) ){ + console.log( item ) data[ item ] = normalizeDate( data[ item ] ) } } diff --git a/v1/src/config/apiConfig.json b/v1/src/config/apiConfig.json index a9a87f7..665eeb9 100644 --- a/v1/src/config/apiConfig.json +++ b/v1/src/config/apiConfig.json @@ -16,7 +16,7 @@ } }, "version" : { - "version" : "1.5.9", + "version" : "1.5.10", "name": "ETA Beta", "date":"22/07/2025" }, diff --git a/v1/src/index.js b/v1/src/index.js index b90a418..69f23db 100644 --- a/v1/src/index.js +++ b/v1/src/index.js @@ -1,6 +1,8 @@ 'use strict'; require('dotenv').config(); const { ROOT_PATH, LIB_PATH, API_CONFIG } = process.env; +process.env.TZ='utc'; + const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` ); const apps = require('./apps'); diff --git a/v1/src/lib/Misc.js b/v1/src/lib/Misc.js index eae701d..3e42509 100644 --- a/v1/src/lib/Misc.js +++ b/v1/src/lib/Misc.js @@ -1,6 +1,7 @@ "use strict"; const apiConfig = require( '../config/apiConfig.json' ); const crypto = require('crypto'); +const moment = require('moment'); const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3'); const s3Client = new S3Client({ @@ -44,13 +45,15 @@ function genKey( len = 6, key="" ){ * @param {*} date */ function normalizeDate( date ){ - let in_date = new Date( date ); - let year = in_date.getFullYear(); - let monthIndex = in_date.getMonth(); - let day = in_date.getDate(); - // new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds); - // return new Date( year, monthIndex, day, 0, 0, 0, 0 ); - return new Date( Date.UTC( year, monthIndex, day, 0, 0, 0, 0 ) ); + process.env.TZ='utc'; + let in_date = moment( date, 'YYYY/MM/DD' ); + let year = in_date.get('year'); + let monthIndex = in_date.get('month'); + let day = in_date.get('date'); + let normalized_date = new Date( year, monthIndex, day, 0, 0, 0, 0 ).toISOString(); + // let normalized_date = moment( in_date, 'YYYY/MM/DD' ).toISOString(); + console.log( `${date} -> ${normalized_date}` ); + return normalized_date; } function getPagination( query ){