mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
fix: clean up rfc3339 function
This commit is contained in:
parent
b0d5e0c2c8
commit
3814d43865
@ -40,13 +40,13 @@ export function fromRfc3339(str: string): Date {
|
|||||||
|
|
||||||
const tzOffset = tzOffsetSign * (tzOffsetHours * 60 + tzOffsetMinutes) * 60; // seconds
|
const tzOffset = tzOffsetSign * (tzOffsetHours * 60 + tzOffsetMinutes) * 60; // seconds
|
||||||
|
|
||||||
let timestamp = Date.UTC(year, month - 1, day, hour, minute, second, milliSeconds);
|
const date = new Date();
|
||||||
|
date.setUTCFullYear(year);
|
||||||
|
date.setUTCMonth(month - 1);
|
||||||
|
date.setUTCDate(day);
|
||||||
|
date.setUTCHours(hour, minute, second, milliSeconds);
|
||||||
|
|
||||||
// Date.UTC maps year 0-99 to 1900-1999. Ensure the correct year is set and THEN apply the offset
|
return new Date(date.getTime() - tzOffset * 1000);
|
||||||
const date = new Date(timestamp);
|
|
||||||
timestamp = date.setUTCFullYear(year) - tzOffset * 1000;
|
|
||||||
|
|
||||||
return new Date(timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toRfc3339(date: Date | ReadonlyDate): string {
|
export function toRfc3339(date: Date | ReadonlyDate): string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user