]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/CDate.py
2 # Purpose: Date and Calendar classes
4 # Author: Lorne White (email: lwhite1@planet.eon.net)
7 # Version 0.2 1999/11/08
8 # Licence: wxWindows license
9 #----------------------------------------------------------------------------
13 Month
= {2: 'February', 3: 'March', None: 0, 'July': 7, 11:
14 'November', 'December': 12, 'June': 6, 'January': 1, 'September': 9,
15 'August': 8, 'March': 3, 'November': 11, 'April': 4, 12: 'December',
16 'May': 5, 10: 'October', 9: 'September', 8: 'August', 7: 'July', 6:
17 'June', 5: 'May', 4: 'April', 'October': 10, 'February': 2, 1:
20 # Number of days per month (except for February in leap years)
21 mdays
= [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
23 # Full and abbreviated names of weekdays
24 day_name
= [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
25 day_abbr
= ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', ]
27 # Return number of leap years in range [y1, y2)
28 # Assume y1 <= y2 and no funny (non-leap century) years
31 return (y2
+3)/4 - (y1
+3)/4
33 # Return 1 for leap years, 0 for non-leap years
35 return year
% 4 == 0 and (year
% 100 <> 0 or year
% 400 == 0)
44 def julianDay(year
, month
, day
):
46 year
, month
, day
= long(year
), long(month
), long(day
)
48 year
= year
+ month
/12L
52 year
= year
- month
/12L - 1L
53 month
= 12L - month
%12L
61 if year
*10000L + month
*100L + day
> 15821014L:
62 b
= 2L - year
/100L + year
/400L
63 return (1461L*year
- yearCorr
)/4L + 306001L*(month
+ 1L)/10000L + day
+ 1720994L + b
67 date
= time
.localtime(time
.time())
71 julian
= julianDay(year
, month
, day
)
72 daywk
= dayOfWeek(julian
)
73 daywk
= day_name
[daywk
]
77 date
= FromFormat(value
)
78 daywk
= DateCalc
.dayOfWeek(date
)
79 daywk
= day_name
[daywk
]
82 def FromJulian(julian
):
84 if (julian
< 2299160L):
87 alpha
= (4L*julian
- 7468861L)/146097L
88 b
= julian
+ 1526L + alpha
- alpha
/4L
89 c
= (20L*b
- 2442L)/7305L
91 e
= 10000L*(b
- d
)/306001L
92 day
= int(b
- d
- 306001L*e
/10000L)
102 return year
, month
, day
104 def dayOfWeek(julian
):
105 return int((julian
+ 1L)%7L)
107 def daysPerMonth(month
, year
):
108 ndays
= mdays
[month
] + (month
== 2 and isleap(year
))
113 self
.date
= time
.localtime(time
.time())
114 self
.year
= self
.date
[0]
115 self
.month
= self
.date
[1]
116 self
.day
= self
.date
[2]
119 def __init__(self
, year
, month
, day
):
120 self
.julian
= julianDay(year
, month
, day
)
123 self
.day_of_week
= dayOfWeek(self
.julian
)
124 self
.days_in_month
= daysPerMonth(self
.month
, self
.year
)