-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build an ISO compliant string - 11507 #12155
Changes from all commits
48bbf8b
36fdc6c
893dc6f
5314819
e89af80
30bacc8
6ac8ad8
5bdb97d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -783,40 +783,13 @@ JulianDate.toIso8601 = function (julianDate, precision) { | |
|
||
let millisecondStr; | ||
|
||
if (!defined(precision) && millisecond !== 0) { | ||
//Forces milliseconds into a number with at least 3 digits to whatever the default toString() precision is. | ||
millisecondStr = (millisecond * 0.01).toString().replace(".", ""); | ||
return `${year.toString().padStart(4, "0")}-${month | ||
.toString() | ||
.padStart(2, "0")}-${day | ||
.toString() | ||
.padStart(2, "0")}T${hour | ||
.toString() | ||
.padStart(2, "0")}:${minute | ||
.toString() | ||
.padStart(2, "0")}:${second | ||
.toString() | ||
.padStart(2, "0")}.${millisecondStr}Z`; | ||
} | ||
|
||
//Precision is either 0 or milliseconds is 0 with undefined precision, in either case, leave off milliseconds entirely | ||
if (!defined(precision) || precision === 0) { | ||
return `${year.toString().padStart(4, "0")}-${month | ||
.toString() | ||
.padStart(2, "0")}-${day | ||
.toString() | ||
.padStart(2, "0")}T${hour | ||
.toString() | ||
.padStart(2, "0")}:${minute | ||
.toString() | ||
.padStart(2, "0")}:${second.toString().padStart(2, "0")}Z`; | ||
} | ||
|
||
//Forces milliseconds into a number with at least 3 digits to whatever the specified precision is. | ||
millisecondStr = (millisecond * 0.01) | ||
.toFixed(precision) | ||
.replace(".", "") | ||
.slice(0, precision); | ||
if (millisecond !== 0 || defined(precision)) { | ||
// Forces milliseconds into a number with the specified precision, without scientific notation | ||
const fractionalSeconds = (second + millisecond * 0.001).toFixed(precision); | ||
const parts = fractionalSeconds.split('.'); | ||
millisecondStr = parts.length > 1 ? parts[1] : ''; | ||
Comment on lines
+788
to
+790
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you expand on why you're adding the seconds here then splitting on the Also the original issue called out that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am splitting on . to separate the fractional part (milliseconds) from the whole seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial thought is that splitting on Also it looks like we have constants for some of these "magic numbers", please swap out |
||
} | ||
|
||
return `${year.toString().padStart(4, "0")}-${month | ||
.toString() | ||
.padStart(2, "0")}-${day | ||
|
@@ -825,9 +798,9 @@ JulianDate.toIso8601 = function (julianDate, precision) { | |
.toString() | ||
.padStart(2, "0")}:${minute | ||
.toString() | ||
.padStart(2, "0")}:${second | ||
.toString() | ||
.padStart(2, "0")}.${millisecondStr}Z`; | ||
.padStart(2, "0")}:${Math.floor(second).toString().padStart(2, "0")}${ | ||
millisecondStr ? `.${millisecondStr}` : '' | ||
}Z`; | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs to happen eventually but it should be it's own PR so it's isolated and we can be sure it's the change we want. This PR should focus only on the date string
I had already opened #12180