Skip to content
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

docs: document parse behavior with non-format strings #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elliotttf
Copy link

I came across this behavior while using ptera to parse ISO strings without milliseconds. It's clear from the tests that this is the intended behavior, but I didn't notice this documented anywhere, so this PR updates the docs to cover the behavior of parse when non-format strings are in play.

Alternatively, the parse function could be updated to only handle format strings. A test to confirm the behavior can be added by applying this diff

diff --git a/parse_date_test.ts b/parse_date_test.ts
index a6729e5..0a64d2e 100644
--- a/parse_date_test.ts
+++ b/parse_date_test.ts
@@ -259,6 +259,21 @@ Deno.test("parseDateStr valid", () => {
         locale: "en",
       },
     },
+    {
+      dateStr: "2021-01-12T01:02:03Z",
+      format: "YYYY-MM-ddTHH:mm:ssZ",
+      expected: {
+        year: 2021,
+        month: 1,
+        day: 12,
+        hour: 1,
+        minute: 2,
+        second: 3,
+        millisecond: 0,
+        offsetMillisec: 0,
+        locale: "en",
+      },
+    },
   ];
   tests.forEach((t) => {
     assertEquals(parseDateStr(t.dateStr, t.format), t.expected);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant