summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorFelix Krause <contact@flyx.org>2016-11-07 11:08:31 +0100
committerFelix Krause <contact@flyx.org>2016-11-07 11:08:31 +0100
commit6e604e2f9f59c75b198e84462a709ba847c519ea (patch)
treeba65a6e4265abfb5a88dd6f0372549f792f67478 /lib
parentf500b9f47beb1026d00f34ec3c87c1b6ec526a7c (diff)
downloadNim-6e604e2f9f59c75b198e84462a709ba847c519ea.tar.gz
More cosmetic changes
 * Don't use factor var, it's overly complicated
 * Removed proc that's now unused
 * Better documented timezone field
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/times.nim31
1 files changed, 11 insertions, 20 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 6aeec24a3..41f513b73 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -147,7 +147,10 @@ type
     isDST*: bool              ## Determines whether DST is in effect. Always
                               ## ``False`` if time is UTC.
     timezone*: int            ## The offset of the (non-DST) timezone in seconds
-                              ## west of UTC.
+                              ## west of UTC. Note that the sign of this number
+                              ## is the opposite of the one in a formatted
+                              ## timezone string like ``+01:00`` (which would be
+                              ## parsed into the timezone ``-3600``).
 
   ## I make some assumptions about the data in here. Either
   ## everything should be positive or everything negative. Zero is
@@ -529,13 +532,6 @@ when not defined(JS):
     # does ignore the timezone, we need to adjust this here.
     result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone)
 
-  proc toStringTillNL(p: cstring): string =
-    result = ""
-    var i = 0
-    while p[i] != '\0' and p[i] != '\10' and p[i] != '\13':
-      add(result, p[i])
-      inc(i)
-
   const
     epochDiff = 116444736000000000'i64
     rateDiff = 10000000'i64 # 100 nsecs
@@ -827,26 +823,21 @@ proc formatToken(info: TimeInfo, token: string, buf: var string) =
     if fyear.len != 5: fyear = repeat('0', 5-fyear.len()) & fyear
     buf.add(fyear)
   of "z":
-    let
-      factor = if info.timezone <= 0: -1 else: 1
-      hours = (factor * info.timezone) div secondsInHour
-    if factor == 1: buf.add('-')
+    let hours = abs(info.timezone) div secondsInHour
+    if info.timezone < 0: buf.add('-')
     else: buf.add('+')
     buf.add($hours)
   of "zz":
-    let
-      factor = if info.timezone <= 0: -1 else: 1
-      hours = (factor * info.timezone) div secondsInHour
-    if factor == 1: buf.add('-')
+    let hours = abs(info.timezone) div secondsInHour
+    if info.timezone < 0: buf.add('-')
     else: buf.add('+')
     if hours < 10: buf.add('0')
     buf.add($hours)
   of "zzz":
     let
-      factor = if info.timezone <= 0: -1 else: 1
-      hours = (factor * info.timezone) div secondsInHour
-      minutes = (factor * info.timezone) mod 60
-    if factor == 1: buf.add('-')
+      hours = abs(info.timezone) div secondsInHour
+      minutes = abs(info.timezone) mod 60
+    if info.timezone < 0: buf.add('-')
     else: buf.add('+')
     if hours < 10: buf.add('0')
     buf.add($hours)