~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/support/parsedatetime/pdtc.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
CalendarConstants defines all constants used by parsedatetime.py.
 
5
"""
 
6
 
 
7
__license__ = """Copyright (c) 2004-2006 Mike Taylor, All rights reserved.
 
8
 
 
9
Licensed under the Apache License, Version 2.0 (the "License");
 
10
you may not use this file except in compliance with the License.
 
11
You may obtain a copy of the License at
 
12
 
 
13
   http://www.apache.org/licenses/LICENSE-2.0
 
14
 
 
15
Unless required by applicable law or agreed to in writing, software
 
16
distributed under the License is distributed on an "AS IS" BASIS,
 
17
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
18
See the License for the specific language governing permissions and
 
19
limitations under the License.
 
20
"""
 
21
__author__       = 'Mike Taylor <http://code-bear.com>'
 
22
__contributors__ = ['Darshana Chhajed <mailto://darshana@osafoundation.org>',
 
23
                   ]
 
24
 
 
25
 
 
26
class CalendarConstants:
 
27
    def __init__(self):
 
28
        self.Locale = 'American'
 
29
 
 
30
        self.TIMESEP      = ':'
 
31
 
 
32
        self.RE_SPECIAL   = r'(?P<special>^[in|on|of|at]+)\s+'
 
33
        self.RE_UNITS     = r'(?P<qty>(-?\d+\s*(?P<units>((hour|hr|minute|min|second|sec|day|dy|week|wk|month|mth|year|yr)s?))))'
 
34
        self.RE_QUNITS    = r'(?P<qty>(-?\d+\s?(?P<qunits>h|m|s|d|w|m|y)(\s|,|$)))'
 
35
        self.RE_MODIFIER  = r'(?P<modifier>(previous|prev|last|next|this|eo|(end\sof)|(in\sa)))'
 
36
        self.RE_MODIFIER2 = r'(?P<modifier>(from|before|after|ago|prior))'
 
37
        self.RE_TIMEHMS   = r'(?P<hours>\d\d?)(?P<tsep>:|)(?P<minutes>\d\d)(?:(?P=tsep)(?P<seconds>\d\d(?:[.,]\d+)?))?'
 
38
        self.RE_TIMEHMS2  = r'(?P<hours>(\d\d?))((?P<tsep>:|)(?P<minutes>(\d\d?))(?:(?P=tsep)(?P<seconds>\d\d?(?:[.,]\d+)?))?)?\s?(?P<meridian>(am|pm|a.m.|p.m.|a|p))'
 
39
        self.RE_DATE      = r'(?P<date>\d+([/.\\]\d+)+)'
 
40
        self.RE_DATE2     = r'[/.\\]'
 
41
        self.RE_DATE3     = r'(?P<date>((?P<mthname>(january|february|march|april|may|june|july|august|september|october|november|december))\s?((?P<day>\d\d?)(\s|rd|st|nd|th|,|$)+)?(?P<year>\d\d\d\d)?))'
 
42
        self.RE_MONTH     = r'(?P<month>((?P<mthname>(january|february|march|april|may|june|july|august|september|october|november|december))(\s?(?P<year>(\d\d\d\d)))?))'
 
43
        self.RE_WEEKDAY   = r'(?P<weekday>(monday|mon|tuesday|tue|wednesday|wed|thursday|thu|friday|fri|saturday|sat|sunday|sun))'
 
44
        self.RE_DAY       = r'(?P<day>(today|tomorrow|yesterday))'
 
45
        self.RE_TIME      = r'\s*(?P<time>(morning|breakfast|noon|lunch|evening|midnight|tonight|dinner|night|now))' 
 
46
        self.RE_REMAINING = r'\s+'
 
47
 
 
48
        # Regex for date/time ranges
 
49
        self.RE_RTIMEHMS   = r'(\d\d?):(\d\d)(:(\d\d))?'
 
50
        self.RE_RTIMEHMS2  = r'(\d\d?)(:(\d\d?))?(:(\d\d?))?\s?(am|pm|a.m.|p.m.|a|p)'
 
51
        self.RE_RDATE      = r'(\d+([/.\\]\d+)+)'
 
52
        self.RE_RDATE3     = r'((((january|february|march|april|may|june|july|august|september|october|november|december))\s?((\d\d?)(\s|rd|st|nd|th|,|$)+)?(\d\d\d\d)?))'
 
53
        self.DATERNG1 = self.RE_RDATE + r'\s?-\s?' + self.RE_RDATE                      #"06/07/06 - 08/09/06"
 
54
        self.DATERNG2 = self.RE_RDATE3 + r'\s?-\s?' + self.RE_RDATE3                    #"march 31 - june 1st, 2006"
 
55
        self.DATERNG3 = self.RE_RDATE3 + r'\s?' + r'-' + r'\s?(\d\d?)\s?(rd|st|nd|th)?' #"march 1rd -13th"
 
56
        self.TIMERNG1 = self.RE_RTIMEHMS2 + r'\s?-\s?'+ self.RE_RTIMEHMS2  #"4:00:55 pm - 5:90:44 am",'4p-5p'
 
57
        self.TIMERNG2 = self.RE_RTIMEHMS + r'\s?-\s?'+ self.RE_RTIMEHMS    #"4:00 - 5:90 ","4:55:55-3:44:55"
 
58
        self.TIMERNG3 = r'\d\d?\s?-\s?'+ self.RE_RTIMEHMS2                 #"4-5pm "
 
59
 
 
60
          # Used to adjust the returned date before/after the source
 
61
 
 
62
        self.Modifiers = { 'from':       1,
 
63
                           'before':    -1,
 
64
                           'after':      1,
 
65
                           'ago':        1,
 
66
                           'prior':     -1,
 
67
                           'prev':      -1,
 
68
                           'last':      -1,
 
69
                           'next':       1,
 
70
                           'this':       0,
 
71
                           'previous':  -1,
 
72
                           'in a':       2,
 
73
                           'end of':     0,
 
74
                           'eo':         0,
 
75
                        }
 
76
 
 
77
        self.Second =   1
 
78
        self.Minute =  60 * self.Second
 
79
        self.Hour   =  60 * self.Minute
 
80
        self.Day    =  24 * self.Hour
 
81
        self.Week   =   7 * self.Day
 
82
        self.Month  =  30 * self.Day
 
83
        self.Year   = 365 * self.Day
 
84
 
 
85
        self.WeekDays = { 'monday':    0,
 
86
                          'mon':       0,
 
87
                          'tuesday':   1,
 
88
                          'tue':       1,
 
89
                          'wednesday': 2,
 
90
                          'wed':       2,
 
91
                          'thursday':  3,
 
92
                          'thu':       3,
 
93
                          'friday':    4,
 
94
                          'fri':       4,
 
95
                          'saturday':  5,
 
96
                          'sat':       5,
 
97
                          'sunday':    6,
 
98
                          'sun':       6,
 
99
                        }
 
100
 
 
101
          # dictionary to allow for locale specific text
 
102
          # NOTE: The keys are the localized values - the parsing
 
103
          #       code will be using Target_Text using the values
 
104
          #       extracted *from* the user's input
 
105
 
 
106
        self.Target_Text = { 'datesep':   '-',
 
107
                             'timesep':   ':',
 
108
                             'day':       'day',
 
109
                             'dy':        'dy',
 
110
                             'd':         'd',
 
111
                             'week':      'week',
 
112
                             'wk':        'wk',
 
113
                             'w':         'w',
 
114
                             'month':     'month',
 
115
                             'mth':       'mth',
 
116
                             'year':      'year',
 
117
                             'yr':        'yr',
 
118
                             'y':         'y',
 
119
                             'hour':      'hour',
 
120
                             'hr':        'hr',
 
121
                             'h':         'h',
 
122
                             'minute':    'minute',
 
123
                             'min':       'min',
 
124
                             'm':         'm',
 
125
                             'second':    'second',
 
126
                             'sec':       'sec',
 
127
                             's':         's',
 
128
                             'now':       'now',
 
129
                             'noon':      'noon',
 
130
                             'morning':   'morning',
 
131
                             'evening':   'evening',
 
132
                             'breakfast': 'breakfast',
 
133
                             'lunch':     'lunch',
 
134
                             'dinner':    'dinner',
 
135
                             'monday':    'monday',
 
136
                             'mon':       'mon',
 
137
                             'tuesday':   'tuesday',
 
138
                             'tue':       'tue',
 
139
                             'wednesday': 'wednesday',
 
140
                             'wed':       'wed',
 
141
                             'thursday':  'thursday',
 
142
                             'thu':       'thu',
 
143
                             'friday':    'friday',
 
144
                             'fri':       'fri',
 
145
                             'saturday':  'saturday',
 
146
                             'sat':       'sat',
 
147
                             'sunday':    'sunday',
 
148
                             'sun':       'sun',
 
149
                             'january':   'january',
 
150
                             'jan':       'jan',
 
151
                             'febuary':   'febuary',
 
152
                             'feb':       'feb',
 
153
                             'march':     'march',
 
154
                             'mar':       'mar',
 
155
                             'april':     'april',
 
156
                             'apr':       'apr',
 
157
                             'may':       'may',
 
158
                             'may':       'may',
 
159
                             'june':      'june',
 
160
                             'jun':       'jun',
 
161
                             'july':      'july',
 
162
                             'jul':       'jul',
 
163
                             'august':    'august',
 
164
                             'aug':       'aug',
 
165
                             'september': 'september',
 
166
                             'sept':      'sep',
 
167
                             'october':   'october',
 
168
                             'oct':       'oct',
 
169
                             'november':  'november',
 
170
                             'nov':       'nov',
 
171
                             'december':  'december',
 
172
                             'dec':       'dec',
 
173
                           }
 
174
 
 
175
          # FIXME: there *has* to be a standard routine that does this
 
176
 
 
177
        self.DOW_Text = [self.Target_Text['mon'],
 
178
                         self.Target_Text['tue'],
 
179
                         self.Target_Text['wed'],
 
180
                         self.Target_Text['thu'],
 
181
                         self.Target_Text['fri'],
 
182
                         self.Target_Text['sat'],
 
183
                         self.Target_Text['sun'],
 
184
                        ]
 
185
 
 
186
        self.DaysInMonthList = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
 
187
 
 
188
        self.DaysInMonth = {}
 
189
        self.DaysInMonth[self.Target_Text['january']]   = self.DaysInMonthList[0]
 
190
        self.DaysInMonth[self.Target_Text['febuary']]   = self.DaysInMonthList[1]
 
191
        self.DaysInMonth[self.Target_Text['march']]     = self.DaysInMonthList[2]
 
192
        self.DaysInMonth[self.Target_Text['april']]     = self.DaysInMonthList[3]
 
193
        self.DaysInMonth[self.Target_Text['may']]       = self.DaysInMonthList[4]
 
194
        self.DaysInMonth[self.Target_Text['june']]      = self.DaysInMonthList[5]
 
195
        self.DaysInMonth[self.Target_Text['july']]      = self.DaysInMonthList[6]
 
196
        self.DaysInMonth[self.Target_Text['august']]    = self.DaysInMonthList[7]
 
197
        self.DaysInMonth[self.Target_Text['september']] = self.DaysInMonthList[8]
 
198
        self.DaysInMonth[self.Target_Text['october']]   = self.DaysInMonthList[9]
 
199
        self.DaysInMonth[self.Target_Text['november']]  = self.DaysInMonthList[10]
 
200
        self.DaysInMonth[self.Target_Text['december']]  = self.DaysInMonthList[11]
 
201
 
 
202
        self.Month_Text = [ self.Target_Text['january'],
 
203
                            self.Target_Text['febuary'],
 
204
                            self.Target_Text['march'],
 
205
                            self.Target_Text['april'],
 
206
                            self.Target_Text['may'],
 
207
                            self.Target_Text['june'],
 
208
                            self.Target_Text['july'],
 
209
                            self.Target_Text['august'],
 
210
                            self.Target_Text['september'],
 
211
                            self.Target_Text['october'],
 
212
                            self.Target_Text['november'],
 
213
                            self.Target_Text['december'],
 
214
                          ]
 
215
 
 
216
 
 
217
        self.MthNames = { 'january':    1,
 
218
                          'february':   2,
 
219
                          'march':      3,
 
220
                          'april':      4,
 
221
                          'may' :       5,
 
222
                          'june':       6,
 
223
                          'july':       7,
 
224
                          'august':     8,
 
225
                          'september':  9,
 
226
                          'october':   10,
 
227
                          'november':  11,
 
228
                          'december':  12,
 
229
                        }
 
230
 
 
231
 
 
232
 
 
233
          # This looks hokey - but it is a nice simple way to get
 
234
          # the proper unit value and it has the advantage that
 
235
          # later I can morph it into something localized.
 
236
          # Any trailing s will be removed before lookup.
 
237
 
 
238
        self.Units = {}
 
239
        self.Units[self.Target_Text['second']] = self.Second
 
240
        self.Units[self.Target_Text['sec']]    = self.Second
 
241
        self.Units[self.Target_Text['s']]      = self.Second
 
242
        self.Units[self.Target_Text['minute']] = self.Minute
 
243
        self.Units[self.Target_Text['min']]    = self.Minute
 
244
        self.Units[self.Target_Text['m']]      = self.Minute
 
245
        self.Units[self.Target_Text['hour']]   = self.Hour
 
246
        self.Units[self.Target_Text['hr']]     = self.Hour
 
247
        self.Units[self.Target_Text['h']]      = self.Hour
 
248
        self.Units[self.Target_Text['day']]    = self.Day
 
249
        self.Units[self.Target_Text['dy']]     = self.Day
 
250
        self.Units[self.Target_Text['d']]      = self.Day
 
251
        self.Units[self.Target_Text['week']]   = self.Week
 
252
        self.Units[self.Target_Text['wk']]     = self.Week
 
253
        self.Units[self.Target_Text['w']]      = self.Week
 
254
        self.Units[self.Target_Text['month']]  = self.Month
 
255
        self.Units[self.Target_Text['mth']]    = self.Month
 
256
        self.Units[self.Target_Text['year']]   = self.Year
 
257
        self.Units[self.Target_Text['yr']]     = self.Year
 
258
        self.Units[self.Target_Text['y']]      = self.Year
 
259
 
 
260
        self.Units_Text = { 'one':        1,
 
261
                            'two':        2,
 
262
                            'three':      3,
 
263
                            'four':       4,
 
264
                            'five':       5,
 
265
                            'six':        6,
 
266
                            'seven':      7,
 
267
                            'eight':      8,
 
268
                            'nine':       9,
 
269
                            'ten':       10,
 
270
                            'eleven':    11,
 
271
                            'twelve':    12,
 
272
                            'thirteen':  13,
 
273
                            'fourteen':  14,
 
274
                            'fifteen':   15,
 
275
                            'sixteen':   16,
 
276
                            'seventeen': 17,
 
277
                            'eighteen':  18,
 
278
                            'nineteen':  19,
 
279
                            'twenty':    20,
 
280
                            'thirty':    30,
 
281
                            'forty':     40,
 
282
                            'fifty':     50,
 
283
                            'sixty':     60,
 
284
                            'seventy':   70,
 
285
                            'eighty':    80,
 
286
                            'ninety':    90,
 
287
                            'half':      0.5,
 
288
                            'quarter':  0.25,
 
289
                         }
 
290