there is no hour 0 in am/pm time
This commit is contained in:
parent
04df7f147c
commit
bf6e82a861
2 changed files with 21 additions and 7 deletions
|
|
@ -1158,8 +1158,12 @@ proc formatToken(dt: DateTime, token: string, buf: var string) =
|
||||||
of "dddd":
|
of "dddd":
|
||||||
buf.add($dt.weekday)
|
buf.add($dt.weekday)
|
||||||
of "h":
|
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":
|
of "hh":
|
||||||
|
if dt.hour == 0:
|
||||||
|
buf.add("12")
|
||||||
|
else:
|
||||||
let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour
|
let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour
|
||||||
if amerHour < 10:
|
if amerHour < 10:
|
||||||
buf.add('0')
|
buf.add('0')
|
||||||
|
|
@ -1488,11 +1492,15 @@ proc parseToken(dt: var DateTime; token, value: string; j: var int) =
|
||||||
dt.second = value[j..j+1].parseInt()
|
dt.second = value[j..j+1].parseInt()
|
||||||
j += 2
|
j += 2
|
||||||
of "t":
|
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
|
dt.hour += 12
|
||||||
j += 1
|
j += 1
|
||||||
of "tt":
|
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
|
dt.hour += 12
|
||||||
j += 2
|
j += 2
|
||||||
of "yy":
|
of "yy":
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ t.checkFormat("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
||||||
|
|
||||||
t.checkFormat("yyyyMMddhhmmss", "20380119031407")
|
t.checkFormat("yyyyMMddhhmmss", "20380119031407")
|
||||||
|
|
||||||
|
# issue 7620
|
||||||
|
let t7620_am = parse("4/15/2017 12:01:02 AM +0", "M/d/yyyy' 'h:mm:ss' 'tt' 'z", utc())
|
||||||
|
t7620_am.checkFormat("M/d/yyyy' 'h:mm:ss' 'tt' 'z", "4/15/2017 12:01:02 AM +0")
|
||||||
|
let t7620_pm = parse("4/15/2017 12:01:02 PM +0", "M/d/yyyy' 'h:mm:ss' 'tt' 'z", utc())
|
||||||
|
t7620_pm.checkFormat("M/d/yyyy' 'h:mm:ss' 'tt' 'z", "4/15/2017 12:01:02 PM +0")
|
||||||
|
|
||||||
let t2 = fromUnix(160070789).utc # Mon 27 Jan 16:06:29 GMT 1975
|
let t2 = fromUnix(160070789).utc # Mon 27 Jan 16:06:29 GMT 1975
|
||||||
t2.checkFormat("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
t2.checkFormat("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",
|
" ss t tt y yy yyy yyyy yyyyy z zz zzz",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue