Let fromRfc3339 return mutable Date type
This commit is contained in:
@@ -7,7 +7,7 @@ function padded(integer: number, length = 2): string {
|
||||
return filled.substring(filled.length - length);
|
||||
}
|
||||
|
||||
export function fromRfc3339(str: string): ReadonlyDate {
|
||||
export function fromRfc3339(str: string): Date {
|
||||
const matches = rfc3339Matcher.exec(str);
|
||||
if (!matches) {
|
||||
throw new Error("Date string is not in RFC3339 format");
|
||||
@@ -40,9 +40,8 @@ export function fromRfc3339(str: string): ReadonlyDate {
|
||||
|
||||
const tzOffset = tzOffsetSign * (tzOffsetHours * 60 + tzOffsetMinutes) * 60; // seconds
|
||||
|
||||
return new ReadonlyDate(
|
||||
ReadonlyDate.UTC(year, month - 1, day, hour, minute, second, milliSeconds) - tzOffset * 1000,
|
||||
);
|
||||
const timestamp = Date.UTC(year, month - 1, day, hour, minute, second, milliSeconds) - tzOffset * 1000;
|
||||
return new Date(timestamp);
|
||||
}
|
||||
|
||||
export function toRfc3339(date: Date | ReadonlyDate): string {
|
||||
|
||||
@@ -12,8 +12,7 @@ export interface DateWithNanoseconds extends Date {
|
||||
}
|
||||
|
||||
export function fromRfc3339WithNanoseconds(dateTimeString: string): DateWithNanoseconds {
|
||||
// fromRfc3339 should give the caller a regular Date directly
|
||||
const out: DateWithNanoseconds = new Date(fromRfc3339(dateTimeString).getTime());
|
||||
const out: DateWithNanoseconds = fromRfc3339(dateTimeString);
|
||||
const nanosecondsMatch = dateTimeString.match(/\.(\d+)Z$/);
|
||||
const nanoseconds = nanosecondsMatch ? nanosecondsMatch[1].slice(3) : "";
|
||||
out.nanoseconds = parseInt(nanoseconds.padEnd(6, "0"), 10);
|
||||
|
||||
Reference in New Issue
Block a user