Python calendar.leapdays() Examples
The following are 30
code examples of calendar.leapdays().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
calendar
, or try the search function
.
Example #1
Source File: http.py From learn_python3_spider with MIT License | 6 votes |
def timegm(year, month, day, hour, minute, second): """ Convert time tuple in GMT to seconds since epoch, GMT """ EPOCH = 1970 if year < EPOCH: raise ValueError("Years prior to %d not supported" % (EPOCH,)) assert 1 <= month <= 12 days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year) for i in range(1, month): days = days + calendar.mdays[i] if month > 2 and calendar.isleap(year): days = days + 1 days = days + day - 1 hours = days*24 + hour minutes = hours*60 + minute seconds = minutes*60 + second return seconds
Example #2
Source File: http.py From python-for-android with Apache License 2.0 | 6 votes |
def timegm(year, month, day, hour, minute, second): """ Convert time tuple in GMT to seconds since epoch, GMT """ EPOCH = 1970 if year < EPOCH: raise ValueError("Years prior to %d not supported" % (EPOCH,)) assert 1 <= month <= 12 days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year) for i in range(1, month): days = days + calendar.mdays[i] if month > 2 and calendar.isleap(year): days = days + 1 days = days + day - 1 hours = days*24 + hour minutes = hours*60 + minute seconds = minutes*60 + second return seconds
Example #3
Source File: http.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def timegm(year, month, day, hour, minute, second): """ Convert time tuple in GMT to seconds since epoch, GMT """ EPOCH = 1970 if year < EPOCH: raise ValueError("Years prior to %d not supported" % (EPOCH,)) assert 1 <= month <= 12 days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year) for i in range(1, month): days = days + calendar.mdays[i] if month > 2 and calendar.isleap(year): days = days + 1 days = days + day - 1 hours = days*24 + hour minutes = hours*60 + minute seconds = minutes*60 + second return seconds
Example #4
Source File: test_calendar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_one_leapday_lower_boundary(self): # test when one leap year in range, lower boundary is leap year self.assertEqual(calendar.leapdays(2012,2013), 1)
Example #5
Source File: date.py From formulas with European Union Public License 1.1 | 5 votes |
def xyearfrac(start_date, end_date, basis=0): raise_errors(basis, start_date, end_date) basis = tuple(flatten(basis, None)) if len(basis) != 1 or isinstance(basis[0], bool): return Error.errors['#VALUE!'] basis = 0 if basis[0] is sh.EMPTY else basis[0] if not is_number(basis) or int(basis) not in (0, 1, 2, 3, 4): return Error.errors['#NUM!'] dates = [tuple(flatten(d, None)) for d in (start_date, end_date)] if any(isinstance(d[0], bool) for d in dates): return Error.errors['#VALUE!'] # noinspection PyTypeChecker basis, dates = int(basis), [xday(*d, slice(0, 3)) for d in dates] err = get_error(*dates) if err: return err (y1, m1, d1), (y2, m2, d2) = sorted(dates) denom = 360 if basis in (0, 4): # US 30/360 & Eurobond 30/360 d1 = min(d1, 30) if basis == 4: d2 = min(d2, 30) elif d1 == 30: d2 = max(d2, 30) n_days = 360 * (y2 - y1) + 30 * (m2 - m1) + (d2 - d1) else: # Actual/actual & Actual/360 & Actual/365 n_days = xdate(y2, m2, d2) - xdate(y1, m1, d1) if basis == 3: denom = 365 elif basis == 1: denom = 365 + calendar.leapdays(y1, y2 + 1) / (y2 - y1 + 1) return n_days / denom
Example #6
Source File: functioncall.py From nml with GNU General Public License v2.0 | 5 votes |
def builtin_date(name, args, pos): """ date(year, month, day) builtin function. @return Days since 1 jan 1 of the given date. """ days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if len(args) != 3: raise generic.ScriptError("date() requires exactly 3 arguments", pos) identifier.ignore_all_invalid_ids = True year = args[0].reduce(global_constants.const_list) identifier.ignore_all_invalid_ids = False try: month = args[1].reduce_constant().value day = args[2].reduce_constant().value except generic.ConstError: raise generic.ScriptError("Month and day parameters of date() should be compile-time constants", pos) generic.check_range(month, 1, 12, "month", args[1].pos) generic.check_range(day, 1, days_in_month[month-1], "day", args[2].pos) if not isinstance(year, ConstantNumeric): if month != 1 or day != 1: raise generic.ScriptError("when the year parameter of date() is not a compile time constant month and day should be 1", pos) #num_days = year*365 + year/4 - year/100 + year/400 part1 = BinOp(nmlop.MUL, year, ConstantNumeric(365)) part2 = BinOp(nmlop.DIV, year, ConstantNumeric(4)) part3 = BinOp(nmlop.DIV, year, ConstantNumeric(100)) part4 = BinOp(nmlop.DIV, year, ConstantNumeric(400)) res = BinOp(nmlop.ADD, part1, part2) res = BinOp(nmlop.SUB, res, part3) res = BinOp(nmlop.ADD, res, part4) return res generic.check_range(year.value, 0, 5000000, "year", year.pos) day_in_year = 0 for i in range(month - 1): day_in_year += days_in_month[i] day_in_year += day if month >= 3 and (year.value % 4 == 0) and ((not year.value % 100 == 0) or (year.value % 400 == 0)): day_in_year += 1 return ConstantNumeric(year.value * 365 + calendar.leapdays(0, year.value) + day_in_year - 1, pos)
Example #7
Source File: test_calendar.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_no_range(self): # test when no range i.e. two identical years as args self.assertEqual(calendar.leapdays(2010,2010), 0)
Example #8
Source File: test_calendar.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_no_leapdays(self): # test when no leap years in range self.assertEqual(calendar.leapdays(2010,2011), 0)
Example #9
Source File: test_calendar.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_no_leapdays_upper_boundary(self): # test no leap years in range, when upper boundary is a leap year self.assertEqual(calendar.leapdays(2010,2012), 0)
Example #10
Source File: test_calendar.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_one_leapday_lower_boundary(self): # test when one leap year in range, lower boundary is leap year self.assertEqual(calendar.leapdays(2012,2013), 1)
Example #11
Source File: test_calendar.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_several_leapyears_in_range(self): self.assertEqual(calendar.leapdays(1997,2020), 5)
Example #12
Source File: test_calendar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_no_range(self): # test when no range i.e. two identical years as args self.assertEqual(calendar.leapdays(2010,2010), 0)
Example #13
Source File: test_calendar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays(self): # test when no leap years in range self.assertEqual(calendar.leapdays(2010,2011), 0)
Example #14
Source File: test_calendar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays_upper_boundary(self): # test no leap years in range, when upper boundary is a leap year self.assertEqual(calendar.leapdays(2010,2012), 0)
Example #15
Source File: test_calendar.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_several_leapyears_in_range(self): self.assertEqual(calendar.leapdays(1997,2020), 5)
Example #16
Source File: test_calendar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_several_leapyears_in_range(self): self.assertEqual(calendar.leapdays(1997,2020), 5)
Example #17
Source File: http.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def timegm(year, month, day, hour, minute, second): """Convert time tuple in GMT to seconds since epoch, GMT""" EPOCH = 1970 assert year >= EPOCH assert 1 <= month <= 12 days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year) for i in range(1, month): days = days + calendar.mdays[i] if month > 2 and calendar.isleap(year): days = days + 1 days = days + day - 1 hours = days*24 + hour minutes = hours*60 + minute seconds = minutes*60 + second return seconds
Example #18
Source File: test_calendar.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_no_range(self): # test when no range i.e. two identical years as args self.assertEqual(calendar.leapdays(2010,2010), 0)
Example #19
Source File: test_calendar.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays(self): # test when no leap years in range self.assertEqual(calendar.leapdays(2010,2011), 0)
Example #20
Source File: test_calendar.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays_upper_boundary(self): # test no leap years in range, when upper boundary is a leap year self.assertEqual(calendar.leapdays(2010,2012), 0)
Example #21
Source File: test_calendar.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_one_leapday_lower_boundary(self): # test when one leap year in range, lower boundary is leap year self.assertEqual(calendar.leapdays(2012,2013), 1)
Example #22
Source File: test_calendar.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_several_leapyears_in_range(self): self.assertEqual(calendar.leapdays(1997,2020), 5)
Example #23
Source File: test_calendar.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_no_range(self): # test when no range i.e. two identical years as args self.assertEqual(calendar.leapdays(2010,2010), 0)
Example #24
Source File: test_calendar.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays(self): # test when no leap years in range self.assertEqual(calendar.leapdays(2010,2011), 0)
Example #25
Source File: test_calendar.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_no_leapdays_upper_boundary(self): # test no leap years in range, when upper boundary is a leap year self.assertEqual(calendar.leapdays(2010,2012), 0)
Example #26
Source File: test_calendar.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_one_leapday_lower_boundary(self): # test when one leap year in range, lower boundary is leap year self.assertEqual(calendar.leapdays(2012,2013), 1)
Example #27
Source File: test_calendar.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_several_leapyears_in_range(self): self.assertEqual(calendar.leapdays(1997,2020), 5)
Example #28
Source File: test_calendar.py From oss-ftp with MIT License | 5 votes |
def test_one_leapday_lower_boundary(self): # test when one leap year in range, lower boundary is leap year self.assertEqual(calendar.leapdays(2012,2013), 1)
Example #29
Source File: test_calendar.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_no_range(self): # test when no range i.e. two identical years as args self.assertEqual(calendar.leapdays(2010,2010), 0)
Example #30
Source File: test_calendar.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_no_leapdays(self): # test when no leap years in range self.assertEqual(calendar.leapdays(2010,2011), 0)