Make the fields of times.DateTime private (#14197)
* Make the fields of `times.DateTime` private * PR fixes
This commit is contained in:
parent
c28a057a6b
commit
48e7775ad1
4 changed files with 208 additions and 88 deletions
|
|
@ -1,7 +1,7 @@
|
|||
discard """
|
||||
output: '''
|
||||
@[2000-01-01T00:00:00+00:00, 2001-01-01T00:00:00+00:00, 2002-01-01T00:00:00+00:00, 2003-01-01T00:00:00+00:00, 2004-01-01T00:00:00+00:00, 2005-01-01T00:00:00+00:00, 2006-01-01T00:00:00+00:00, 2007-01-01T00:00:00+00:00, 2008-01-01T00:00:00+00:00, 2009-01-01T00:00:00+00:00, 2010-01-01T00:00:00+00:00, 2011-01-01T00:00:00+00:00, 2012-01-01T00:00:00+00:00, 2013-01-01T00:00:00+00:00, 2014-01-01T00:00:00+00:00, 2015-01-01T00:00:00+00:00]
|
||||
@[2000-01-01T00:00:00+00:00, 2001-01-01T00:00:00+00:00, 2002-01-01T00:00:00+00:00, 2003-01-01T00:00:00+00:00, 2004-01-01T00:00:00+00:00, 2005-01-01T00:00:00+00:00, 2006-01-01T00:00:00+00:00, 2007-01-01T00:00:00+00:00, 2008-01-01T00:00:00+00:00, 2009-01-01T00:00:00+00:00, 2010-01-01T00:00:00+00:00, 2011-01-01T00:00:00+00:00, 2012-01-01T00:00:00+00:00, 2013-01-01T00:00:00+00:00, 2014-01-01T00:00:00+00:00, 2015-01-01T00:00:00+00:00]
|
||||
@[2000-01-01T00:00:00Z, 2001-01-01T00:00:00Z, 2002-01-01T00:00:00Z, 2003-01-01T00:00:00Z, 2004-01-01T00:00:00Z, 2005-01-01T00:00:00Z, 2006-01-01T00:00:00Z, 2007-01-01T00:00:00Z, 2008-01-01T00:00:00Z, 2009-01-01T00:00:00Z, 2010-01-01T00:00:00Z, 2011-01-01T00:00:00Z, 2012-01-01T00:00:00Z, 2013-01-01T00:00:00Z, 2014-01-01T00:00:00Z, 2015-01-01T00:00:00Z]
|
||||
@[2000-01-01T00:00:00Z, 2001-01-01T00:00:00Z, 2002-01-01T00:00:00Z, 2003-01-01T00:00:00Z, 2004-01-01T00:00:00Z, 2005-01-01T00:00:00Z, 2006-01-01T00:00:00Z, 2007-01-01T00:00:00Z, 2008-01-01T00:00:00Z, 2009-01-01T00:00:00Z, 2010-01-01T00:00:00Z, 2011-01-01T00:00:00Z, 2012-01-01T00:00:00Z, 2013-01-01T00:00:00Z, 2014-01-01T00:00:00Z, 2015-01-01T00:00:00Z]
|
||||
'''
|
||||
"""
|
||||
|
||||
|
|
@ -12,11 +12,11 @@ import times
|
|||
|
||||
# 1
|
||||
proc f(n: int): DateTime =
|
||||
DateTime(year: n, month: mJan, monthday: 1)
|
||||
initDateTime(1, mJan, n, 0, 0, 0, utc())
|
||||
|
||||
echo toSeq(2000 || 2015).map(f)
|
||||
|
||||
# 2
|
||||
echo toSeq(2000 || 2015).map(proc (n: int): DateTime =
|
||||
DateTime(year: n, month: mJan, monthday: 1)
|
||||
initDateTime(1, mJan, n, 0, 0, 0, utc())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -617,17 +617,28 @@ suite "ttimes":
|
|||
test "default DateTime": # https://github.com/nim-lang/RFCs/issues/211
|
||||
var num = 0
|
||||
for ai in Month: num.inc
|
||||
doAssert num == 12
|
||||
check num == 12
|
||||
|
||||
var a: DateTime
|
||||
doAssert a == DateTime.default
|
||||
doAssert ($a).len > 0 # no crash
|
||||
doAssert a.month.Month.ord == 0
|
||||
doAssert a.month.Month == cast[Month](0)
|
||||
doAssert a.monthday == 0
|
||||
check a == DateTime.default
|
||||
check not a.isInitialized
|
||||
check $a == "Uninitialized DateTime"
|
||||
|
||||
doAssertRaises(AssertionDefect): discard getDayOfWeek(a.monthday, a.month, a.year)
|
||||
doAssertRaises(AssertionDefect): discard a.toTime
|
||||
expect(AssertionDefect): discard getDayOfWeek(a.monthday, a.month, a.year)
|
||||
expect(AssertionDefect): discard a.toTime
|
||||
expect(AssertionDefect): discard a.utc()
|
||||
expect(AssertionDefect): discard a.local()
|
||||
expect(AssertionDefect): discard a.inZone(utc())
|
||||
expect(AssertionDefect): discard a + initDuration(seconds = 1)
|
||||
expect(AssertionDefect): discard a + initTimeInterval(seconds = 1)
|
||||
expect(AssertionDefect): discard a.isLeapDay
|
||||
expect(AssertionDefect): discard a < a
|
||||
expect(AssertionDefect): discard a <= a
|
||||
expect(AssertionDefect): discard getDateStr(a)
|
||||
expect(AssertionDefect): discard getClockStr(a)
|
||||
expect(AssertionDefect): discard a.format "yyyy"
|
||||
expect(AssertionDefect): discard a.format initTimeFormat("yyyy")
|
||||
expect(AssertionDefect): discard between(a, a)
|
||||
|
||||
test "inX procs":
|
||||
doAssert initDuration(seconds = 1).inSeconds == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue