]>
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 08-Nov-1999
8 # Licence: wxWindows license
9 #----------------------------------------------------------------------------
10 # Updated: 01-Dec-2004
11 # Action: Cast the year variable to an integer under the Date Class
12 # Reason: When the year was compared in the isleap() function, if it was
13 # in a string format, then an error was raised.
17 Month
= {2: 'February', 3: 'March', None: 0, 'July': 7, 11:
18 'November', 'December': 12, 'June': 6, 'January': 1, 'September': 9,
19 'August': 8, 'March': 3, 'November': 11, 'April': 4, 12: 'December',
20 'May': 5, 10: 'October', 9: 'September', 8: 'August', 7: 'July', 6:
21 'June', 5: 'May', 4: 'April', 'October': 10, 'February': 2, 1:
24 # Number of days per month (except for February in leap years)
25 mdays
= [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
27 # Full and abbreviated names of weekdays
28 day_name
= [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
29 day_abbr
= ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', ]
31 # Return number of leap years in range [y1, y2)
32 # Assume y1 <= y2 and no funny (non-leap century) years
35 return (y2
+3)/4 - (y1
+3)/4
37 # Return 1 for leap years, 0 for non-leap years
39 return year
% 4 == 0 and (year
% 100 <> 0 or year
% 400 == 0)
48 def julianDay(year
, month
, day
):
50 year
, month
, day
= long(year
), long(month
), long(day
)
52 year
= year
+ month
/12L
56 year
= year
- month
/12L - 1L
57 month
= 12L - month
%12L
65 if year
*10000L + month
*100L + day
> 15821014L:
66 b
= 2L - year
/100L + year
/400L
67 return (1461L*year
- yearCorr
)/4L + 306001L*(month
+ 1L)/10000L + day
+ 1720994L + b
71 date
= time
.localtime(time
.time())
75 julian
= julianDay(year
, month
, day
)
76 daywk
= dayOfWeek(julian
)
77 daywk
= day_name
[daywk
]
81 date
= FromFormat(value
)
82 daywk
= DateCalc
.dayOfWeek(date
)
83 daywk
= day_name
[daywk
]
86 def FromJulian(julian
):
88 if (julian
< 2299160L):
91 alpha
= (4L*julian
- 7468861L)/146097L
92 b
= julian
+ 1526L + alpha
- alpha
/4L
93 c
= (20L*b
- 2442L)/7305L
95 e
= 10000L*(b
- d
)/306001L
96 day
= int(b
- d
- 306001L*e
/10000L)
106 return year
, month
, day
108 def dayOfWeek(julian
):
109 return int((julian
+ 1L)%7L)
111 def daysPerMonth(month
, year
):
112 ndays
= mdays
[month
] + (month
== 2 and isleap(year
))
117 self
.date
= time
.localtime(time
.time())
118 self
.year
= self
.date
[0]
119 self
.month
= self
.date
[1]
120 self
.day
= self
.date
[2]
123 def __init__(self
, year
, month
, day
):
124 self
.julian
= julianDay(year
, month
, day
)
126 self
.year
= int(year
)
127 self
.day_of_week
= dayOfWeek(self
.julian
)
128 self
.days_in_month
= daysPerMonth(self
.month
, self
.year
)