-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3354 from energywebfoundation/irec-respect-timezone
fix(irec): respect timezone when formatting date (device, issue) to year-month-day
- Loading branch information
Showing
4 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/traceability/issuer-irec-api-wrapper/src/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Formats date object to date (YYYY-MM-DD). | ||
* It respects timezone only if `process.env.TZ` is set. | ||
* If not, it will format date for UTC. | ||
*/ | ||
export const timeToTimezoneDate = (time?: Date) => { | ||
if (!time) { | ||
return time; | ||
} | ||
|
||
if (process.env.TZ) { | ||
const year = time.getFullYear(); | ||
const month = time.getMonth() + 1; | ||
const day = time.getDate(); | ||
|
||
return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`; | ||
} else { | ||
return time.toISOString().split('T')[0]; | ||
} | ||
}; |