本文整理汇总了Python中datetime.MINYEAR属性的典型用法代码示例。如果您正苦于以下问题:Python datetime.MINYEAR属性的具体用法?Python datetime.MINYEAR怎么用?Python datetime.MINYEAR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类datetime
的用法示例。
在下文中一共展示了datetime.MINYEAR属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bad_constructor_arguments
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_bad_constructor_arguments(self):
# bad years
self.theclass(MINYEAR, 1, 1) # no exception
self.theclass(MAXYEAR, 1, 1) # no exception
self.assertRaises(ValueError, self.theclass, MINYEAR-1, 1, 1)
self.assertRaises(ValueError, self.theclass, MAXYEAR+1, 1, 1)
# bad months
self.theclass(2000, 1, 1) # no exception
self.theclass(2000, 12, 1) # no exception
self.assertRaises(ValueError, self.theclass, 2000, 0, 1)
self.assertRaises(ValueError, self.theclass, 2000, 13, 1)
# bad days
self.theclass(2000, 2, 29) # no exception
self.theclass(2004, 2, 29) # no exception
self.theclass(2400, 2, 29) # no exception
self.assertRaises(ValueError, self.theclass, 2000, 2, 30)
self.assertRaises(ValueError, self.theclass, 2001, 2, 29)
self.assertRaises(ValueError, self.theclass, 2100, 2, 29)
self.assertRaises(ValueError, self.theclass, 1900, 2, 29)
self.assertRaises(ValueError, self.theclass, 2000, 1, 0)
self.assertRaises(ValueError, self.theclass, 2000, 1, 32)
示例2: get_time
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def get_time(item):
"""
>>> date = get_time({"time": "2015-01-04T15:40:44Z"}) # doctest: +NORMALIZE_WHITESPACE
>>> date.utctimetuple() # doctest: +NORMALIZE_WHITESPACE
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=4, tm_hour=15, tm_min=40,
tm_sec=44, tm_wday=6, tm_yday=4, tm_isdst=0)
>>> date = get_time({"date": "2015-01-04T15:40:44Z"})
>>> date.utctimetuple() # doctest: +NORMALIZE_WHITESPACE
time.struct_time(tm_year=2015, tm_mon=1, tm_mday=4, tm_hour=15, tm_min=40,
tm_sec=44, tm_wday=6, tm_yday=4, tm_isdst=0)
>>> date = get_time({})
>>> date.utctimetuple() # doctest: +NORMALIZE_WHITESPACE
time.struct_time(tm_year=0, tm_mon=12, tm_mday=31, tm_hour=21, tm_min=58,
tm_sec=0, tm_wday=6, tm_yday=366, tm_isdst=0)
"""
if item.get('time', ''):
bid_time = iso8601.parse_date(item['time'])
elif item.get('date', ''):
bid_time = iso8601.parse_date(item['date'])
else:
bid_time = datetime(MINYEAR, 1, 1, tzinfo=timezone('Europe/Kiev'))
return bid_time
示例3: _check_year
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def _check_year(year):
"""Check if year is a valid year.
:param year: The year to test
:return: The year
:rtype: int
:raises TypeError: If year is not an int or int-like string
:raises ValueError: If year is out of range
"""
year = _check_int(year)
if datetime.MINYEAR <= year <= datetime.MAXYEAR:
return year
else:
raise ValueError('year must be in %d..%d' % (
datetime.MINYEAR, datetime.MAXYEAR), year)
示例4: test_constants
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_constants(self):
import datetime
self.assertEqual(datetime.MINYEAR, 1)
self.assertEqual(datetime.MAXYEAR, 9999)
#############################################################################
# tzinfo tests
示例5: test_constants
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_constants(self):
datetime = datetime_module
self.assertEqual(datetime.MINYEAR, 1)
self.assertEqual(datetime.MAXYEAR, 9999)
示例6: set_date
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def set_date(self, year, month, day):
try:
date(year, month, day)
except Exception as e:
print(e)
if str(e) == "day is out of range for month":
raise self.SetDateError(" Day %s day is out of range for month %s" % (day, month))
elif str(e) == "month must be in 1..12":
raise self.SetDateError("Month must be between 1 and 12, got %s" % month)
elif str(e) == "year is out of range":
raise self.SetDateError("Year must be between %s and %s, got %s" %
(datetime.MINYEAR, datetime.MAXYEAR, year))
else:
self.sel_year = year
self.sel_month = month
self.sel_day = day
self.month = self.sel_month
self.year = self.sel_year
self.day = self.sel_day
self.update_cal_matrix(self.sel_year, self.sel_month)
self.set_month_day(self.sel_day)
self.selector.update()
示例7: test_datetime_values
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_datetime_values(self):
""" Tests for CASSANDRA-9399, check tables with date and time values"""
self.cluster.populate(1)
self.cluster.start(wait_for_binary_proto=True)
node1, = self.cluster.nodelist()
stdout, stderr = self.run_cqlsh(node1, cmds="""
CREATE KEYSPACE datetime_checks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE datetime_checks;
CREATE TABLE values (d date, t time, PRIMARY KEY (d, t));
INSERT INTO values (d, t) VALUES ('9800-12-31', '23:59:59.999999999');
INSERT INTO values (d, t) VALUES ('2015-05-14', '16:30:00.555555555');
INSERT INTO values (d, t) VALUES ('1582-1-1', '00:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%d-1-1', '00:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%d-1-1', '01:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%d-1-1', '02:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%d-1-1', '03:00:00.000000000')"""
% (datetime.MINYEAR - 1, datetime.MINYEAR, datetime.MAXYEAR, datetime.MAXYEAR + 1,))
# outside the MIN and MAX range it should print the number of days from the epoch
assert 0 == len(stderr), "Failed to execute cqlsh: {}".format(stderr)
self.verify_output("select * from datetime_checks.values", node1, """
d | t
------------+--------------------
-719528 | 00:00:00.000000000
9800-12-31 | 23:59:59.999999999
0001-01-01 | 01:00:00.000000000
1582-01-01 | 00:00:00.000000000
2932897 | 03:00:00.000000000
9999-01-01 | 02:00:00.000000000
2015-05-14 | 16:30:00.555555555
""")
self.verify_output("DESCRIBE TABLE datetime_checks.values", node1, """
CREATE TABLE datetime_checks.values (
d date,
t time,
PRIMARY KEY (d, t)
""")
示例8: test_datetime_values_40
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_datetime_values_40(self):
self.cluster.populate(1)
self.cluster.start(wait_for_binary_proto=True)
node1, = self.cluster.nodelist()
stdout, stderr = self.run_cqlsh(node1, cmds="""
CREATE KEYSPACE datetime_checks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE datetime_checks;
CREATE TABLE values (d date, t time, PRIMARY KEY (d, t));
INSERT INTO values (d, t) VALUES ('9800-12-31', '23:59:59.999999999');
INSERT INTO values (d, t) VALUES ('2015-05-14', '16:30:00.555555555');
INSERT INTO values (d, t) VALUES ('1582-01-01', '00:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%04d-01-01', '00:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%04d-01-01', '01:00:00.000000000');
INSERT INTO values (d, t) VALUES ('%02d-01-01', '02:00:00.000000000');
INSERT INTO values (d, t) VALUES ('+%02d-01-01', '03:00:00.000000000')"""
% (datetime.MINYEAR - 1, datetime.MINYEAR, datetime.MAXYEAR, datetime.MAXYEAR+1))
assert 0 == len(stderr), "Failed to execute cqlsh: {}".format(stderr)
self.verify_output("select * from datetime_checks.values", node1, """
d | t
------------+--------------------
-719528 | 00:00:00.000000000
9800-12-31 | 23:59:59.999999999
0001-01-01 | 01:00:00.000000000
1582-01-01 | 00:00:00.000000000
2932897 | 03:00:00.000000000
9999-01-01 | 02:00:00.000000000
2015-05-14 | 16:30:00.555555555
""")
self.verify_output("DESCRIBE TABLE datetime_checks.values", node1, """
CREATE TABLE datetime_checks.values (
d date,
t time,
PRIMARY KEY (d, t)
""")
示例9: address_info
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def address_info(self):
conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME')
if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval:
# converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time
addresses = None
try:
if self.ipc:
addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)]
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
except (socket.gaierror, AttributeError):
pass
if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags
try:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP)
except socket.gaierror:
pass
if addresses:
self._address_info = [list(address) + [None, None] for address in addresses]
self._address_info_resolved_time = datetime.now()
else:
self._address_info = []
self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date
if log_enabled(BASIC):
for address in self._address_info:
log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2])
return self._address_info
示例10: refresh
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def refresh(self):
self.servers = []
for server in self.server_pool.servers:
self.servers.append([server, datetime(MINYEAR, 1, 1), True]) # server, smallest date ever, supposed available
self.last_used_server = randint(0, len(self.servers) - 1)
示例11: address_info
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def address_info(self):
conf_refresh_interval = get_config_parameter('ADDRESS_INFO_REFRESH_TIME')
if not self._address_info or (datetime.now() - self._address_info_resolved_time).seconds > conf_refresh_interval:
# converts addresses tuple to list and adds a 6th parameter for availability (None = not checked, True = available, False=not available) and a 7th parameter for the checking time
addresses = None
try:
if self.ipc:
addresses = [(socket.AF_UNIX, socket.SOCK_STREAM, 0, None, self.host, None)]
else:
if self.mode == IP_V4_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
elif self.mode == IP_V6_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG | socket.AI_V4MAPPED)
except (socket.gaierror, AttributeError):
pass
if not addresses: # if addresses not found or raised an exception (for example for bad flags) tries again without flags
try:
if self.mode == IP_V4_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
elif self.mode == IP_V6_ONLY:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP)
else:
addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP)
except socket.gaierror:
pass
if addresses:
self._address_info = [list(address) + [None, None] for address in addresses]
self._address_info_resolved_time = datetime.now()
else:
self._address_info = []
self._address_info_resolved_time = datetime(MINYEAR, 1, 1) # smallest date
if log_enabled(BASIC):
for address in self._address_info:
log(BASIC, 'address for <%s> resolved as <%r>', self, address[:-2])
return self._address_info
示例12: refresh
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def refresh(self):
self.server_states = []
for server in self.server_pool.servers:
self.server_states.append(ServerState(server, datetime(MINYEAR, 1, 1), True)) # server, smallest date ever, supposed available
self.last_used_server = randint(0, len(self.server_states) - 1)
示例13: test_name_cleanup
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def test_name_cleanup(self):
if '_Fast' not in str(self):
return
datetime = datetime_module
names = set(name for name in dir(datetime)
if not name.startswith('__') and not name.endswith('__'))
allowed = set(['MAXYEAR', 'MINYEAR', 'date', 'datetime',
'datetime_CAPI', 'time', 'timedelta', 'timezone',
'tzinfo'])
self.assertEqual(names - allowed, set([]))
示例14: weekday
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import MINYEAR [as 别名]
def weekday(year, month, day):
"""Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31)."""
if not datetime.MINYEAR <= year <= datetime.MAXYEAR:
year = 2000 + year % 400
return datetime.date(year, month, day).weekday()