summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/times.nim61
1 files changed, 29 insertions, 32 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 442f46d7e..69d9b8966 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -26,9 +26,6 @@ type
   WeekDay* = enum ## represents a weekday
     dMon, dTue, dWed, dThu, dFri, dSat, dSun
 
-const
-    digits = {'0','1','2','3','4','5','6','7','8','9'}
-
 var
   timezone {.importc, header: "<time.h>".}: int
   tzname {.importc, header: "<time.h>" .}: array[0..1, cstring]
@@ -780,15 +777,15 @@ proc parseToken(info: var TimeInfo; token, value: string; j: var int) =
     ## Helper of the parse proc to parse individual tokens.
     case token
     of "d":
-        if value[j+1] in digits:
-            #two digit format
+        if value[j+1] in Digits:
+            # two digit format
             info.monthday = value[j..j+1].parseInt()
             j += 2
         else:
             info.monthday = parseInt($value[j])
             j += 1
     of "dd":
-        #two digit format
+        # two digit format
         info.monthday = value[j..j+1].parseInt()
         j += 2
     of "ddd":
@@ -835,33 +832,33 @@ proc parseToken(info: var TimeInfo; token, value: string; j: var int) =
         else:
             raise newException(ValueError, "invalid day of week ")    
     of "h", "H":
-        if value[j+1] in digits:
-            #two digit format
+        if value[j+1] in Digits:
+            # two digit format
             info.hour = value[j..j+1].parseInt()
             j += 2
         else:
             info.hour = parseInt($value[j])
             j += 1
     of "hh", "HH":
-        #two digit format
+        # two digit format
         info.hour = value[j..j+1].parseInt()
         j += 2
     of "m":
-        if value[j+1] in digits:
-            #two digit format
+        if value[j+1] in Digits:
+            # two digit format
             info.minute = value[j..j+1].parseInt()
             j += 2
         else:
             info.minute = parseInt($value[j])
             j += 1
     of "mm":
-        #two digit format
+        # two digit format
         info.minute = value[j..j+1].parseInt()
         j += 2
     of "M":
         var month: int
-        if value[j+1] in digits:
-            #two digit format
+        if value[j+1] in Digits:
+            # two digit format
             month = value[j..j+1].parseInt()
             j += 2
         else:
@@ -941,15 +938,15 @@ proc parseToken(info: var TimeInfo; token, value: string; j: var int) =
         else:
             raise newException(ValueError, "invalid month") 
     of "s":
-        if value[j+1] in digits:
-            #two digit format
+        if value[j+1] in Digits:
+            # two digit format
             info.second = value[j..j+1].parseInt()
             j += 2
         else:
             info.second = parseInt($value[j])
             j += 1
     of "ss":
-        #two digit format
+        # two digit format
         info.second = value[j..j+1].parseInt()
         j += 2
     of "t":
@@ -961,7 +958,7 @@ proc parseToken(info: var TimeInfo; token, value: string; j: var int) =
             info.hour += 12
         j += 2
     of "yy":
-        #Assumes current century
+        # Assumes current century
         var year = value[j..j+1].parseInt()
         var thisCen = getLocalTime(getTime()).year div 100
         info.year = thisCen*100 + year
@@ -997,7 +994,7 @@ proc parseToken(info: var TimeInfo; token, value: string; j: var int) =
         info.tzname = value[j..j+2].toUpper()
         j += 3
     else:
-        #Ignore the token and move forward in the value string by the same length
+        # Ignore the token and move forward in the value string by the same length
         j += token.len
     
 proc parse*(value, layout: string): TimeInfo =
@@ -1038,10 +1035,10 @@ proc parse*(value, layout: string): TimeInfo =
     ## inserted without quoting them: ``:`` ``-`` ``(`` ``)`` ``/`` ``[`` ``]``
     ## ``,``. However you don't need to necessarily separate format specifiers, a
     ## unambiguous format string like ``yyyyMMddhhmmss`` is valid too.    
-    var i = 0 #pointer for format string
-    var j = 0 #pointer for value string
+    var i = 0 # pointer for format string
+    var j = 0 # pointer for value string
     var token = ""
-    #Assumes current day of week, month and year, but time is reset to 00:00:00
+    # Assumes current day of week, month and year, but time is reset to 00:00:00
     var info = getLocalTime(getTime())
     info.hour = 0
     info.minute = 0
@@ -1051,12 +1048,12 @@ proc parse*(value, layout: string): TimeInfo =
         of ' ', '-', '/', ':', '\'', '\0', '(', ')', '[', ']', ',':
             if token.len > 0:
                 parseToken(info, token, value, j)
-            #Reset token
+            # Reset token
             token = ""
-            #Break if at end of line
+            # Break if at end of line
             if layout[i] == '\0': break
-            #Skip separator and everything between single quotes
-            #These are literals in both the layout and the value string
+            # Skip separator and everything between single quotes
+            # These are literals in both the layout and the value string
             if layout[i] == '\'':
                 inc(i)
                 inc(j)
@@ -1098,12 +1095,12 @@ when isMainModule:
     " ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") ==
     "27 27 Mon Monday 4 04 16 16 6 06 1 01 Jan January 29 29 P PM 5 75 975 1975 01975 0 00 00:00 UTC"
   
-  # when not defined(JS) and sizeof(Time) == 8:
-  #   var t3 = getGMTime(fromSeconds(889067643645)) # Fri  7 Jun 19:20:45 BST 30143
-  #   assert t3.format("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
-  #     " ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") == 
-  #     "7 07 Fri Friday 6 06 18 18 20 20 6 06 Jun June 45 45 P PM 3 43 143 0143 30143 0 00 00:00 UTC"
-  #   assert t3.format(":,[]()-/") == ":,[]()-/" 
+  when not defined(JS) and sizeof(Time) == 8:
+    var t3 = getGMTime(fromSeconds(889067643645)) # Fri  7 Jun 19:20:45 BST 30143
+    assert t3.format("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
+      " ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") == 
+      "7 07 Fri Friday 6 06 18 18 20 20 6 06 Jun June 45 45 P PM 3 43 143 0143 30143 0 00 00:00 UTC"
+    assert t3.format(":,[]()-/") == ":,[]()-/" 
   
   var t4 = getGMTime(fromSeconds(876124714)) # Mon  6 Oct 08:58:34 BST 1997
   assert t4.format("M MM MMM MMMM") == "10 10 Oct October"
l&id=3b7ef2288f60bc5c355ad9aeaa127431ec3aee7b'>^
eb8e267ff ^
7063670a2 ^
7be092bba ^


47dce2688 ^

e25474154 ^
7be092bba ^
2df9b442c ^
2df9b442c ^
e25474154 ^
2df9b442c ^



e25474154 ^

7be092bba ^
7063670a2 ^
e25474154 ^
7063670a2 ^
bdd9f971e ^
7063670a2 ^


2df9b442c ^
7be092bba ^


e25474154 ^
7be092bba ^
7be092bba ^
e25474154 ^
23ef565a3 ^
b731e6ef1 ^
7063670a2 ^
e25474154 ^

7be092bba ^
7be092bba ^
defc7bbde ^

e25474154 ^
baeec1180 ^




351e89e70 ^

db51eb3e3 ^
351e89e70 ^


47335aab4 ^
70ea45cdb ^
351e89e70 ^
baeec1180 ^

e4081a720 ^
baeec1180 ^


2df9b442c ^
351e89e70 ^
7be092bba ^

cd0256136 ^




170573a87 ^
8dda362fa ^
7be092bba ^
212457f5e ^
78f4aacde ^

af7c92c00 ^






af7c92c00 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137