Make the fields of times.DateTime private (#14197)

* Make the fields of `times.DateTime` private

* PR fixes
This commit is contained in:
Oscar Nihlgård 2020-05-06 12:20:34 +02:00 • committed by GitHub
commit 48e7775ad1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 208 additions and 88 deletions

View file

@ -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())
)

View file

@ -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