diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2018-05-03 16:07:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-03 16:07:27 +0100 |
commit | f7f69b1abbd7de8f61dd3fc1f5d901f04d06928b (patch) | |
tree | 384cb9a658095f17e36399d7918b8105bdde8ce9 /lib | |
parent | 3829d9081c4767384d2ad7e0e124c726c14f4849 (diff) | |
parent | bf6e82a8611428fde85a0017166f316599c4228e (diff) | |
download | Nim-f7f69b1abbd7de8f61dd3fc1f5d901f04d06928b.tar.gz |
Merge pull request #7624 from skilchen/fix-issue7620
there is no hour 0 in am/pm time (see #7620)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/times.nim | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index bc8a50fd7..f6567cf58 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -1173,12 +1173,16 @@ proc formatToken(dt: DateTime, token: string, buf: var string) = of "dddd": buf.add($dt.weekday) of "h": - buf.add($(if dt.hour > 12: dt.hour - 12 else: dt.hour)) + if dt.hour == 0: buf.add("12") + else: buf.add($(if dt.hour > 12: dt.hour - 12 else: dt.hour)) of "hh": - let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour - if amerHour < 10: - buf.add('0') - buf.add($amerHour) + if dt.hour == 0: + buf.add("12") + else: + let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour + if amerHour < 10: + buf.add('0') + buf.add($amerHour) of "H": buf.add($dt.hour) of "HH": @@ -1503,11 +1507,15 @@ proc parseToken(dt: var DateTime; token, value: string; j: var int) = dt.second = value[j..j+1].parseInt() j += 2 of "t": - if value[j] == 'P' and dt.hour > 0 and dt.hour < 12: + if value[j] == 'A' and dt.hour == 12: + dt.hour = 0 + elif value[j] == 'P' and dt.hour > 0 and dt.hour < 12: dt.hour += 12 j += 1 of "tt": - if value[j..j+1] == "PM" and dt.hour > 0 and dt.hour < 12: + if value[j..j+1] == "AM" and dt.hour == 12: + dt.hour = 0 + elif value[j..j+1] == "PM" and dt.hour > 0 and dt.hour < 12: dt.hour += 12 j += 2 of "yy": |