Skip to content

Instantly share code, notes, and snippets.

@moskytw
Last active December 18, 2015 18:49
Show Gist options
  • Save moskytw/5828799 to your computer and use it in GitHub Desktop.
Save moskytw/5828799 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
for y in (2011, 2012, 2100, 2400):
print 'year:', y
for m in range(1, 12+1):
m_days = 30 + (m+(m>=8))%2 - 2*(m==2) + (m==2 and (not y%4 and not not y%100 or not y%400))
print m, m_days
print
# output:
# year: 2011
# 1 31
# 2 28
# 3 31
# 4 30
# 5 31
# 6 30
# 7 31
# 8 31
# 9 30
# 10 31
# 11 30
# 12 31
#
# year: 2012
# 1 31
# 2 29
# 3 31
# 4 30
# 5 31
# 6 30
# 7 31
# 8 31
# 9 30
# 10 31
# 11 30
# 12 31
#
# year: 2100
# 1 31
# 2 28
# 3 31
# 4 30
# 5 31
# 6 30
# 7 31
# 8 31
# 9 30
# 10 31
# 11 30
# 12 31
#
# year: 2400
# 1 31
# 2 29
# 3 31
# 4 30
# 5 31
# 6 30
# 7 31
# 8 31
# 9 30
# 10 31
# 11 30
# 12 31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment