summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorlit <litlighilit@foxmail.com>2024-07-23 09:56:36 +0800
committerGitHub <noreply@github.com>2024-07-23 09:56:36 +0800
commit03973dca30828aea5cc189d551be34d22d10b7b4 (patch)
tree1384a1c24b290c913e7811a3de51b662126b6cff
parent881fbb8f81599c6f633158618f05fa05439816ca (diff)
downloadNim-03973dca30828aea5cc189d551be34d22d10b7b4.tar.gz
doc,test(times): followup #23861 (#23881)
followup #23861
-rw-r--r--lib/pure/times.nim7
-rw-r--r--tests/stdlib/ttimes.nim14
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index da130d35e..e59153455 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -131,9 +131,10 @@
   ===========  =================================================================================  ==============================================
 
   Other strings can be inserted by putting them in `''`. For example
-  `hh'->'mm` will give `01->56`.  The following characters can be
-  inserted without quoting them: `:` `-` `(` `)` `/` `[` `]`
-  `,`. A literal `'` can be specified with `''`.
+  `hh'->'mm` will give `01->56`.  In addition to spaces,
+  the following characters can be inserted without quoting them:
+  `:` `-` `,` `.` `(` `)` `/` `[` `]`.
+  A literal `'` can be specified with `''`.
 
   However you don't need to necessarily separate format patterns, as an
   unambiguous format string like `yyyyMMddhhmmss` is also valid (although
diff --git a/tests/stdlib/ttimes.nim b/tests/stdlib/ttimes.nim
index 602552f95..0f04168dc 100644
--- a/tests/stdlib/ttimes.nim
+++ b/tests/stdlib/ttimes.nim
@@ -71,7 +71,7 @@ template runTimezoneTests() =
       "2006-01-12T22:04:05Z", 11)
   # RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
   parseTest("2006-01-12T15:04:05.999999999Z-07:00",
-      "yyyy-MM-dd'T'HH:mm:ss'.999999999Z'zzz", "2006-01-12T22:04:05Z", 11)
+      "yyyy-MM-dd'T'HH:mm:ss.'999999999Z'zzz", "2006-01-12T22:04:05Z", 11)
   for tzFormat in ["z", "zz", "zzz"]:
     # formatting timezone as 'Z' for UTC
     parseTest("2001-01-12T22:04:05Z", "yyyy-MM-dd'T'HH:mm:ss" & tzFormat,
@@ -770,3 +770,15 @@ block: # ttimes
     proc test(): DateTime {.gcsafe.} =
       result = "1970".parse("yyyy")
     doAssert test().year == 1970
+
+  block: # test FormatLiterals
+    # since #23861
+    block:
+      let dt = dateTime(2024, mJul, 21, 17, 01, 02, 123_321_123, utc())
+      check dt.format("ss.fff") == "02.123"
+      check dt.format("fff.ffffff") == "123.123321"
+    block:
+      let dt = parse("2024.07.21", "yyyy.MM.dd")
+      check dt.year == 2024
+      check dt.month == mJul
+      check dt.monthday == 21