More cosmetic changes

* Don't use factor var, it's overly complicated
 * Removed proc that's now unused
 * Better documented timezone field
This commit is contained in:
Felix Krause 2016-11-07 11:08:31 +01:00
commit 6e604e2f9f

View file

@ -147,7 +147,10 @@ type
isDST*: bool ## Determines whether DST is in effect. Always isDST*: bool ## Determines whether DST is in effect. Always
## ``False`` if time is UTC. ## ``False`` if time is UTC.
timezone*: int ## The offset of the (non-DST) timezone in seconds 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 ## I make some assumptions about the data in here. Either
## everything should be positive or everything negative. Zero is ## 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. # does ignore the timezone, we need to adjust this here.
result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) 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 const
epochDiff = 116444736000000000'i64 epochDiff = 116444736000000000'i64
rateDiff = 10000000'i64 # 100 nsecs 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 if fyear.len != 5: fyear = repeat('0', 5-fyear.len()) & fyear
buf.add(fyear) buf.add(fyear)
of "z": of "z":
let let hours = abs(info.timezone) div secondsInHour
factor = if info.timezone <= 0: -1 else: 1 if info.timezone < 0: buf.add('-')
hours = (factor * info.timezone) div secondsInHour
if factor == 1: buf.add('-')
else: buf.add('+') else: buf.add('+')
buf.add($hours) buf.add($hours)
of "zz": of "zz":
let let hours = abs(info.timezone) div secondsInHour
factor = if info.timezone <= 0: -1 else: 1 if info.timezone < 0: buf.add('-')
hours = (factor * info.timezone) div secondsInHour
if factor == 1: buf.add('-')
else: buf.add('+') else: buf.add('+')
if hours < 10: buf.add('0') if hours < 10: buf.add('0')
buf.add($hours) buf.add($hours)
of "zzz": of "zzz":
let let
factor = if info.timezone <= 0: -1 else: 1 hours = abs(info.timezone) div secondsInHour
hours = (factor * info.timezone) div secondsInHour minutes = abs(info.timezone) mod 60
minutes = (factor * info.timezone) mod 60 if info.timezone < 0: buf.add('-')
if factor == 1: buf.add('-')
else: buf.add('+') else: buf.add('+')
if hours < 10: buf.add('0') if hours < 10: buf.add('0')
buf.add($hours) buf.add($hours)