mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +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
|
||||
|
||||
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
|
||||
const date = new Date(timestamp);
|
||||
timestamp = date.setUTCFullYear(year) - tzOffset * 1000;
|
||||
|
||||
return new Date(timestamp);
|
||||
return new Date(date.getTime() - tzOffset * 1000);
|
||||
}
|
||||
|
||||
export function toRfc3339(date: Date | ReadonlyDate): string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user