本文整理汇总了Python中lsst.daf.base.DateTime.toString方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.toString方法的具体用法?Python DateTime.toString怎么用?Python DateTime.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.daf.base.DateTime
的用法示例。
在下文中一共展示了DateTime.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFracSecs
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testFracSecs(self):
ts = DateTime("2004-03-01T12:39:45.1Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.100000000Z')
ts = DateTime("2004-03-01T12:39:45.01Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.010000000Z')
ts = DateTime("2004-03-01T12:39:45.000000001Z", DateTime.UTC) # nanosecond
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.000000001Z')
ts = DateTime("2004-03-01T12:39:45.0000000001Z", DateTime.UTC) # too small
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.000000000Z')
示例2: testIsoThrow
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoThrow(self):
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04-01T23:36:05", DateTime.UTC) # Z time zone required for UTC
for scale in (DateTime.TAI, DateTime.TT):
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04-01T23:36:05Z", scale) # Z time zone forbidden for TAI or TT
for scale in self.timeScales:
with self.assertRaises(pexExcept.DomainError):
DateTime("20090401", scale) # time required
with self.assertRaises(pexExcept.DomainError):
DateTime("20090401T", DateTime.UTC) # time required
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04-01T", DateTime.UTC) # time required
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04-01T23:36:05-0700", DateTime.UTC) # time zone offset not supported
with self.assertRaises(pexExcept.DomainError):
DateTime("2009/04/01T23:36:05Z", DateTime.UTC) # "/" not valid
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04-01T23:36", DateTime.UTC) # partial time
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04", DateTime.UTC) # partial date without time
with self.assertRaises(pexExcept.DomainError):
DateTime("2009-04T23:36.05", DateTime.UTC) # partial date with time
with self.assertRaises(pexExcept.DomainError):
DateTime("09-04-01T23:36:05", DateTime.UTC) # 2 digit year
# earliest allowed UTC date is the earliest date in the leap second table
try:
minLeapSecUTC = "1961-01-01T00:00:00Z"
dt = DateTime(minLeapSecUTC, DateTime.UTC)
dt.toString(DateTime.UTC)
except Exception:
self.fail("minLeapSecUTC={} failed, but should be OK".format(minLeapSecUTC))
with self.assertRaises(pexExcept.DomainError):
DateTime("1960-01-01T23:59:59Z", DateTime.UTC) # just before leap second table starts
# earliest allowed date for TAI and TT is year = 1902
for timeSys in (DateTime.TAI, DateTime.TT):
try:
earliestDate = "1902-01-01T00:00:00"
dt = DateTime(earliestDate, timeSys)
dt.toString(DateTime.TAI)
dt.toString(DateTime.TT)
except Exception:
self.fail("{} system={} failed, but should be OK".format(earliestDate, timeSys))
# dates before the leap second table can be created using TAI or TT, but not viewed in UTC
earlyDt = DateTime("1960-01-01T00:00:00", DateTime.TAI)
with self.assertRaises(pexExcept.DomainError):
earlyDt.toString(DateTime.UTC)
with self.assertRaises(pexExcept.DomainError):
DateTime("1901-12-12T23:59:59Z", DateTime.TAI) # too early
with self.assertRaises(pexExcept.DomainError):
DateTime("1700-01-01T00:00:00Z", DateTime.TAI) # way too early
with self.assertRaises(pexExcept.DomainError):
DateTime("2262-01-01T00:00:00Z", DateTime.TAI) # too late
with self.assertRaises(pexExcept.DomainError):
DateTime("3200-01-01T00:00:00Z", DateTime.TAI) # way too late
示例3: testInvalid
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testInvalid(self):
ts = DateTime()
self.assertFalse(ts.isValid())
for scale in self.timeScales:
self.assertEqual(ts.nsecs(scale), DateTime.invalid_nsecs)
for system in self.dateSystems:
with self.assertRaises(RuntimeError):
ts.get(system, scale)
with self.assertRaises(RuntimeError):
ts.gmtime(scale)
with self.assertRaises(RuntimeError):
ts.timespec(scale)
with self.assertRaises(RuntimeError):
ts.timeval(scale)
with self.assertRaises(RuntimeError):
ts.toString(scale)
self.assertEqual(repr(ts), "DateTime()")
示例4: testIsoNonUTCBasics
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoNonUTCBasics(self):
"""Test basic ISO string input and output of TAI and TT dates"""
for scale in (DateTime.TAI, DateTime.TT):
for dateSep in ("-", ""): # "-" date separator is optional
for timeSep in (":", ""): # ":" time separator is optional
for decPt in (".", ","): # "." or "," may be used as decimal point
dateStr = "2009{0}04{0}02T07{1}26{1}39{2}314159265".format(dateSep, timeSep, decPt)
ts = DateTime(dateStr, scale)
self.assertEqual(ts.toString(scale), "2009-04-02T07:26:39.314159265")
self.assertTrue(ts.isValid())
示例5: testIsoUTCBasic
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoUTCBasic(self):
"""Test basic ISO string input and output of UTC dates"""
for dateSep in ("-", ""): # "-" date separator is optional
for timeSep in (":", ""): # ":" time separator is optional
for decPt in (".", ","): # "." or "," may be used as decimal point
dateStr = "2009{0}04{0}02T07{1}26{1}39{2}314159265Z".format(dateSep, timeSep, decPt)
ts = DateTime(dateStr, DateTime.UTC)
self.assertEqual(ts.nsecs(DateTime.TT), 1238657265498159265)
self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265)
self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265)
self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
示例6: testNegative
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testNegative(self):
ts = DateTime("1969-03-01T00:00:32Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-03-01T00:00:32.000000000Z')
ts = DateTime("1969-01-01T00:00:00Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-01-01T00:00:00.000000000Z')
ts = DateTime("1969-01-01T00:00:40Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-01-01T00:00:40.000000000Z')
ts = DateTime("1969-01-01T00:00:38Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-01-01T00:00:38.000000000Z')
ts = DateTime("1969-03-01T12:39:45Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-03-01T12:39:45.000000000Z')
ts = DateTime("1969-03-01T12:39:45.000000001Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-03-01T12:39:45.000000001Z')
self.assertTrue(ts.isValid())
# Note slight inaccuracy in UTC-TAI-UTC round-trip
ts = DateTime("1969-03-01T12:39:45.12345Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-03-01T12:39:45.123449996Z')
ts = DateTime("1969-03-01T12:39:45.123456Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-03-01T12:39:45.123455996Z')
ts = DateTime(-1, DateTime.TAI)
self.assertEqual(ts.toString(ts.UTC), '1969-12-31T23:59:51.999918239Z')
ts = DateTime(0, DateTime.TAI)
self.assertEqual(ts.toString(ts.UTC), '1969-12-31T23:59:51.999918240Z')
ts = DateTime(1, DateTime.TAI)
self.assertEqual(ts.toString(ts.UTC), '1969-12-31T23:59:51.999918241Z')
ts = DateTime(-1, DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1969-12-31T23:59:59.999999999Z')
ts = DateTime(0, DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1970-01-01T00:00:00.000000000Z')
ts = DateTime(1, DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '1970-01-01T00:00:00.000000001Z')
示例7: testIsoNoNSecs
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoNoNSecs(self):
ts = DateTime("2009-04-02T07:26:39Z", DateTime.UTC)
self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233000000000)
self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199000000000)
self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.000000000Z")
self.assertTrue(ts.isValid())
示例8: testIsoExpanded
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoExpanded(self):
ts = DateTime("2009-04-02T07:26:39.314159265Z", DateTime.UTC)
self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265)
self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265)
self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
self.assertTrue(ts.isValid())
示例9: testIsoEpoch
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoEpoch(self):
ts = DateTime("19700101T000000Z", DateTime.UTC)
self.assertEqual(ts.nsecs(DateTime.UTC), 0)
self.assertEqual(ts.toString(ts.UTC), "1970-01-01T00:00:00.000000000Z")
示例10: testIsoBasic
# 需要导入模块: from lsst.daf.base import DateTime [as 别名]
# 或者: from lsst.daf.base.DateTime import toString [as 别名]
def testIsoBasic(self):
ts = DateTime("20090402T072639.314159265Z")
self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265L)
self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265L)
self.assertEqual(ts.toString(), "2009-04-02T07:26:39.314159265Z")