annotate MoinMoin/support/parsedatetime/parsedatetime_consts.py @ 5185:0a6fe22644e3

updated parsedatetime to 0.8.7
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 04 Oct 2009 19:32:01 +0200
parents 62177a952833
children
rev   line source
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1 #!/usr/bin/env python
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
2
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
3 """
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
4 parsedatetime constants and helper functions to determine
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
5 regex values from Locale information if present.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
6
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
7 Also contains the internal Locale classes to give some sane
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
8 defaults if PyICU is not found.
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
9 """
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
10
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
11 __license__ = """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
12 Copyright (c) 2004-2008 Mike Taylor
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
13 Copyright (c) 2006-2008 Darshana Chhajed
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
14 Copyright (c) 2007 Bernd Zeimetz <bzed@debian.org>
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
15 All rights reserved.
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
16
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
17 Licensed under the Apache License, Version 2.0 (the "License");
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
18 you may not use this file except in compliance with the License.
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
19 You may obtain a copy of the License at
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
20
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
21 http://www.apache.org/licenses/LICENSE-2.0
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
22
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
23 Unless required by applicable law or agreed to in writing, software
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
24 distributed under the License is distributed on an "AS IS" BASIS,
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
25 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
26 See the License for the specific language governing permissions and
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
27 limitations under the License.
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
28 """
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
29
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
30 try:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
31 import PyICU as pyicu
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
32 except:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
33 pyicu = None
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
34
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
35
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
36 import datetime
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
37 import calendar
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
38 import time
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
39 import re
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
40
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
41
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
42 class pdtLocale_en:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
43 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
44 en_US Locale constants
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
45
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
46 This class will be used to initialize L{Constants} if PyICU is not located.
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
47
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
48 Defined as class variables are the lists and strings needed by parsedatetime
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
49 to evaluate strings for USA
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
50 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
51
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
52 localeID = 'en_US' # don't use a unicode string
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
53 dateSep = [ u'/', u'.' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
54 timeSep = [ u':' ]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
55 meridian = [ u'AM', u'PM' ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
56 usesMeridian = True
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
57 uses24 = False
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
58
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
59 Weekdays = [ u'monday', u'tuesday', u'wednesday',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
60 u'thursday', u'friday', u'saturday', u'sunday',
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
61 ]
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
62 shortWeekdays = [ u'mon', u'tues', u'wed',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
63 u'thu', u'fri', u'sat', u'sun',
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
64 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
65 Months = [ u'january', u'february', u'march',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
66 u'april', u'may', u'june',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
67 u'july', u'august', u'september',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
68 u'october', u'november', u'december',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
69 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
70 shortMonths = [ u'jan', u'feb', u'mar',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
71 u'apr', u'may', u'jun',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
72 u'jul', u'aug', u'sep',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
73 u'oct', u'nov', u'dec',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
74 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
75 dateFormats = { 'full': 'EEEE, MMMM d, yyyy',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
76 'long': 'MMMM d, yyyy',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
77 'medium': 'MMM d, yyyy',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
78 'short': 'M/d/yy',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
79 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
80 timeFormats = { 'full': 'h:mm:ss a z',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
81 'long': 'h:mm:ss a z',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
82 'medium': 'h:mm:ss a',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
83 'short': 'h:mm a',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
84 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
85
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
86 dp_order = [ u'm', u'd', u'y' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
87
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
88 # this will be added to re_consts later
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
89 units = { 'seconds': [ 'second', 'sec' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
90 'minutes': [ 'minute', 'min' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
91 'hours': [ 'hour', 'hr' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
92 'days': [ 'day', 'dy' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
93 'weeks': [ 'week', 'wk' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
94 'months': [ 'month', 'mth' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
95 'years': [ 'year', 'yr' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
96 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
97
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
98 # text constants to be used by regex's later
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
99 re_consts = { 'specials': 'in|on|of|at',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
100 'timeseperator': ':',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
101 'rangeseperator': '-',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
102 'daysuffix': 'rd|st|nd|th',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
103 'meridian': 'am|pm|a.m.|p.m.|a|p',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
104 'qunits': 'h|m|s|d|w|m|y',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
105 'now': [ 'now' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
106 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
107
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
108 # Used to adjust the returned date before/after the source
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
109 modifiers = { 'from': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
110 'before': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
111 'after': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
112 'ago': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
113 'prior': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
114 'prev': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
115 'last': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
116 'next': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
117 'previous': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
118 'in a': 2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
119 'end of': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
120 'eod': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
121 'eo': 0
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
122 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
123
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
124 dayoffsets = { 'tomorrow': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
125 'today': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
126 'yesterday': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
127 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
128
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
129 # special day and/or times, i.e. lunch, noon, evening
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
130 # each element in the dictionary is a dictionary that is used
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
131 # to fill in any value to be replace - the current date/time will
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
132 # already have been populated by the method buildSources
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
133 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
134 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
135 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
136 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
137 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
138 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
139 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
140 'night': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
141 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
142 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
143 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
144
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
145
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
146 class pdtLocale_au:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
147 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
148 en_AU Locale constants
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
149
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
150 This class will be used to initialize L{Constants} if PyICU is not located.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
151
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
152 Defined as class variables are the lists and strings needed by parsedatetime
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
153 to evaluate strings for Australia
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
154 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
155
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
156 localeID = 'en_AU' # don't use a unicode string
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
157 dateSep = [ u'-', u'/' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
158 timeSep = [ u':' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
159 meridian = [ u'AM', u'PM' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
160 usesMeridian = True
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
161 uses24 = False
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
162
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
163 Weekdays = [ u'monday', u'tuesday', u'wednesday',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
164 u'thursday', u'friday', u'saturday', u'sunday',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
165 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
166 shortWeekdays = [ u'mon', u'tues', u'wed',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
167 u'thu', u'fri', u'sat', u'sun',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
168 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
169 Months = [ u'january', u'february', u'march',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
170 u'april', u'may', u'june',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
171 u'july', u'august', u'september',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
172 u'october', u'november', u'december',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
173 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
174 shortMonths = [ u'jan', u'feb', u'mar',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
175 u'apr', u'may', u'jun',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
176 u'jul', u'aug', u'sep',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
177 u'oct', u'nov', u'dec',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
178 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
179 dateFormats = { 'full': 'EEEE, d MMMM yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
180 'long': 'd MMMM yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
181 'medium': 'dd/MM/yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
182 'short': 'd/MM/yy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
183 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
184 timeFormats = { 'full': 'h:mm:ss a z',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
185 'long': 'h:mm:ss a',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
186 'medium': 'h:mm:ss a',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
187 'short': 'h:mm a',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
188 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
189
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
190 dp_order = [ u'd', u'm', u'y' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
191
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
192 # this will be added to re_consts later
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
193 units = { 'seconds': [ 'second', 'sec' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
194 'minutes': [ 'minute', 'min' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
195 'hours': [ 'hour', 'hr' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
196 'days': [ 'day', 'dy' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
197 'weeks': [ 'week', 'wk' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
198 'months': [ 'month', 'mth' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
199 'years': [ 'year', 'yr' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
200 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
201
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
202 # text constants to be used by regex's later
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
203 re_consts = { 'specials': 'in|on|of|at',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
204 'timeseperator': ':',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
205 'rangeseperator': '-',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
206 'daysuffix': 'rd|st|nd|th',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
207 'meridian': 'am|pm|a.m.|p.m.|a|p',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
208 'qunits': 'h|m|s|d|w|m|y',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
209 'now': [ 'now' ],
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
210 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
211
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
212 # Used to adjust the returned date before/after the source
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
213 modifiers = { 'from': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
214 'before': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
215 'after': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
216 'ago': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
217 'prior': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
218 'prev': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
219 'last': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
220 'next': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
221 'previous': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
222 'in a': 2,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
223 'end of': 0,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
224 'eo': 0,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
225 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
226
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
227 dayoffsets = { 'tomorrow': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
228 'today': 0,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
229 'yesterday': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
230 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
231
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
232 # special day and/or times, i.e. lunch, noon, evening
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
233 # each element in the dictionary is a dictionary that is used
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
234 # to fill in any value to be replace - the current date/time will
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
235 # already have been populated by the method buildSources
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
236 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
237 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
238 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
239 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
240 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
241 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
242 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
243 'night': { 'hr': 21, 'mn': 0, 'sec': 0 },
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
244 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 },
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
245 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 },
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
246 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
247
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
248
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
249 class pdtLocale_es:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
250 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
251 es Locale constants
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
252
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
253 This class will be used to initialize L{Constants} if PyICU is not located.
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
254
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
255 Defined as class variables are the lists and strings needed by parsedatetime
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
256 to evaluate strings in Spanish
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
257
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
258 Note that I don't speak Spanish so many of the items below are still in English
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
259 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
260
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
261 localeID = 'es' # don't use a unicode string
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
262 dateSep = [ u'/' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
263 timeSep = [ u':' ]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
264 meridian = []
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
265 usesMeridian = False
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
266 uses24 = True
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
267
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
268 Weekdays = [ u'lunes', u'martes', u'mi\xe9rcoles',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
269 u'jueves', u'viernes', u's\xe1bado', u'domingo',
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
270 ]
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
271 shortWeekdays = [ u'lun', u'mar', u'mi\xe9',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
272 u'jue', u'vie', u's\xe1b', u'dom',
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
273 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
274 Months = [ u'enero', u'febrero', u'marzo',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
275 u'abril', u'mayo', u'junio',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
276 u'julio', u'agosto', u'septiembre',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
277 u'octubre', u'noviembre', u'diciembre'
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
278 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
279 shortMonths = [ u'ene', u'feb', u'mar',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
280 u'abr', u'may', u'jun',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
281 u'jul', u'ago', u'sep',
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
282 u'oct', u'nov', u'dic'
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
283 ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
284 dateFormats = { 'full': "EEEE d' de 'MMMM' de 'yyyy",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
285 'long': "d' de 'MMMM' de 'yyyy",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
286 'medium': "dd-MMM-yy",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
287 'short': "d/MM/yy",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
288 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
289 timeFormats = { 'full': "HH'H'mm' 'ss z",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
290 'long': "HH:mm:ss z",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
291 'medium': "HH:mm:ss",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
292 'short': "HH:mm",
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
293 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
294
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
295 dp_order = [ u'd', u'm', u'y' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
296
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
297 # this will be added to re_consts later
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
298 units = { 'seconds': [ 'second', 'sec' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
299 'minutes': [ 'minute', 'min' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
300 'hours': [ 'hour', 'hr' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
301 'days': [ 'day', 'dy' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
302 'weeks': [ 'week', 'wk' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
303 'months': [ 'month', 'mth' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
304 'years': [ 'year', 'yr' ],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
305 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
306
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
307 # text constants to be used by regex's later
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
308 re_consts = { 'specials': 'in|on|of|at',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
309 'timeseperator': timeSep,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
310 'dateseperator': dateSep,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
311 'rangeseperator': '-',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
312 'daysuffix': 'rd|st|nd|th',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
313 'qunits': 'h|m|s|d|w|m|y',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
314 'now': [ 'now' ],
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
315 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
316
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
317 # Used to adjust the returned date before/after the source
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
318 modifiers = { 'from': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
319 'before': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
320 'after': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
321 'ago': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
322 'prior': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
323 'prev': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
324 'last': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
325 'next': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
326 'previous': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
327 'in a': 2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
328 'end of': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
329 'eo': 0,
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
330 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
331
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
332 dayoffsets = { 'tomorrow': 1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
333 'today': 0,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
334 'yesterday': -1,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
335 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
336
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
337 # special day and/or times, i.e. lunch, noon, evening
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
338 # each element in the dictionary is a dictionary that is used
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
339 # to fill in any value to be replace - the current date/time will
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
340 # already have been populated by the method buildSources
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
341 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
342 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
343 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
344 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
345 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
346 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
347 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
348 'night': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
349 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
350 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
351 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
352
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
353
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
354 class pdtLocale_de:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
355 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
356 de_DE Locale constants
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
357
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
358 This class will be used to initialize L{Constants} if PyICU is not located.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
359
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
360 Contributed by Debian parsedatetime package maintainer Bernd Zeimetz <bzed@debian.org>
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
361
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
362 Defined as class variables are the lists and strings needed by parsedatetime
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
363 to evaluate strings for German
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
364 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
365
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
366 localeID = 'de_DE' # don't use a unicode string
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
367 dateSep = [ u'.' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
368 timeSep = [ u':' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
369 meridian = [ ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
370 usesMeridian = False
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
371 uses24 = True
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
372
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
373 Weekdays = [ u'montag', u'dienstag', u'mittwoch',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
374 u'donnerstag', u'freitag', u'samstag', u'sonntag',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
375 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
376 shortWeekdays = [ u'mo', u'di', u'mi',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
377 u'do', u'fr', u'sa', u'so',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
378 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
379 Months = [ u'januar', u'februar', u'm\xe4rz',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
380 u'april', u'mai', u'juni',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
381 u'juli', u'august', u'september',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
382 u'oktober', u'november', u'dezember',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
383 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
384 shortMonths = [ u'jan', u'feb', u'mrz',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
385 u'apr', u'mai', u'jun',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
386 u'jul', u'aug', u'sep',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
387 u'okt', u'nov', u'dez',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
388 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
389 dateFormats = { 'full': u'EEEE, d. MMMM yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
390 'long': u'd. MMMM yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
391 'medium': u'dd.MM.yyyy',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
392 'short': u'dd.MM.yy'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
393 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
394
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
395 timeFormats = { 'full': u'HH:mm:ss v',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
396 'long': u'HH:mm:ss z',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
397 'medium': u'HH:mm:ss',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
398 'short': u'HH:mm'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
399 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
400
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
401 dp_order = [ u'd', u'm', u'y' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
402
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
403 # this will be added to re_consts later
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
404 units = { 'seconds': [ 'sekunden', 'sek', 's' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
405 'minutes': [ 'minuten', 'min' , 'm' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
406 'hours': [ 'stunden', 'std', 'h' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
407 'days': [ 'tage', 't' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
408 'weeks': [ 'wochen', 'w' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
409 'months': [ 'monate' ], #the short version would be a capital M,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
410 #as I understand it we can't distinguis
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
411 #between m for minutes and M for months.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
412 'years': [ 'jahre', 'j' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
413 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
414
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
415 # text constants to be used by regex's later
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
416 re_consts = { 'specials': 'am|dem|der|im|in|den|zum',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
417 'timeseperator': ':',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
418 'rangeseperator': '-',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
419 'daysuffix': '',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
420 'qunits': 'h|m|s|t|w|m|j',
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
421 'now': [ 'jetzt' ],
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
422 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
423
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
424 # Used to adjust the returned date before/after the source
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
425 #still looking for insight on how to translate all of them to german.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
426 modifiers = { u'from': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
427 u'before': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
428 u'after': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
429 u'vergangener': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
430 u'vorheriger': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
431 u'prev': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
432 u'letzter': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
433 u'n\xe4chster': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
434 u'dieser': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
435 u'previous': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
436 u'in a': 2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
437 u'end of': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
438 u'eod': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
439 u'eo': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
440 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
441
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
442 #morgen/abermorgen does not work, see http://code.google.com/p/parsedatetime/issues/detail?id=19
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
443 dayoffsets = { u'morgen': 1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
444 u'heute': 0,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
445 u'gestern': -1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
446 u'vorgestern': -2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
447 u'\xfcbermorgen': 2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
448 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
449
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
450 # special day and/or times, i.e. lunch, noon, evening
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
451 # each element in the dictionary is a dictionary that is used
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
452 # to fill in any value to be replace - the current date/time will
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
453 # already have been populated by the method buildSources
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
454 re_sources = { u'mittag': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
455 u'mittags': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
456 u'mittagessen': { 'hr': 12, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
457 u'morgen': { 'hr': 6, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
458 u'morgens': { 'hr': 6, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
459 u'fr\e4hst\xe4ck': { 'hr': 8, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
460 u'abendessen': { 'hr': 19, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
461 u'abend': { 'hr': 18, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
462 u'abends': { 'hr': 18, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
463 u'mitternacht': { 'hr': 0, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
464 u'nacht': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
465 u'nachts': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
466 u'heute abend': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
467 u'heute nacht': { 'hr': 21, 'mn': 0, 'sec': 0 },
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
468 u'feierabend': { 'hr': 17, 'mn': 0, 'sec': 0 },
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
469 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
470
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
471
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
472 pdtLocales = { 'en_US': pdtLocale_en,
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
473 'en_AU': pdtLocale_au,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
474 'es_ES': pdtLocale_es,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
475 'de_DE': pdtLocale_de,
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
476 }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
477
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
478
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
479 def _initLocale(ptc):
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
480 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
481 Helper function to initialize the different lists and strings
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
482 from either PyICU or one of the internal pdt Locales and store
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
483 them into ptc.
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
484 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
485
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
486 def lcase(x):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
487 return x.lower()
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
488
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
489 if pyicu and ptc.usePyICU:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
490 ptc.icuLocale = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
491
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
492 if ptc.localeID is not None:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
493 ptc.icuLocale = pyicu.Locale(ptc.localeID)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
494
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
495 if ptc.icuLocale is None:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
496 for id in range(0, len(ptc.fallbackLocales)):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
497 ptc.localeID = ptc.fallbackLocales[id]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
498 ptc.icuLocale = pyicu.Locale(ptc.localeID)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
499
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
500 if ptc.icuLocale is not None:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
501 break
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
502
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
503 ptc.icuSymbols = pyicu.DateFormatSymbols(ptc.icuLocale)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
504
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
505 # grab ICU list of weekdays, skipping first entry which
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
506 # is always blank
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
507 wd = map(lcase, ptc.icuSymbols.getWeekdays()[1:])
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
508 swd = map(lcase, ptc.icuSymbols.getShortWeekdays()[1:])
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
509
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
510 # store them in our list with Monday first (ICU puts Sunday first)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
511 ptc.Weekdays = wd[1:] + wd[0:1]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
512 ptc.shortWeekdays = swd[1:] + swd[0:1]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
513 ptc.Months = map(lcase, ptc.icuSymbols.getMonths())
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
514 ptc.shortMonths = map(lcase, ptc.icuSymbols.getShortMonths())
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
515
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
516 # not quite sure how to init this so for now
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
517 # set it to none so it will be set to the en_US defaults for now
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
518 ptc.re_consts = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
519 ptc.icu_df = { 'full': pyicu.DateFormat.createDateInstance(pyicu.DateFormat.kFull, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
520 'long': pyicu.DateFormat.createDateInstance(pyicu.DateFormat.kLong, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
521 'medium': pyicu.DateFormat.createDateInstance(pyicu.DateFormat.kMedium, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
522 'short': pyicu.DateFormat.createDateInstance(pyicu.DateFormat.kShort, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
523 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
524 ptc.icu_tf = { 'full': pyicu.DateFormat.createTimeInstance(pyicu.DateFormat.kFull, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
525 'long': pyicu.DateFormat.createTimeInstance(pyicu.DateFormat.kLong, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
526 'medium': pyicu.DateFormat.createTimeInstance(pyicu.DateFormat.kMedium, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
527 'short': pyicu.DateFormat.createTimeInstance(pyicu.DateFormat.kShort, ptc.icuLocale),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
528 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
529 ptc.dateFormats = { 'full': ptc.icu_df['full'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
530 'long': ptc.icu_df['long'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
531 'medium': ptc.icu_df['medium'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
532 'short': ptc.icu_df['short'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
533 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
534 ptc.timeFormats = { 'full': ptc.icu_tf['full'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
535 'long': ptc.icu_tf['long'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
536 'medium': ptc.icu_tf['medium'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
537 'short': ptc.icu_tf['short'].toPattern(),
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
538 }
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
539 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
540 if not ptc.localeID in pdtLocales:
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
541 for id in range(0, len(ptc.fallbackLocales)):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
542 ptc.localeID = ptc.fallbackLocales[id]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
543
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
544 if ptc.localeID in pdtLocales:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
545 break
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
546
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
547 ptc.locale = pdtLocales[ptc.localeID]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
548 ptc.usePyICU = False
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
549
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
550 ptc.Weekdays = ptc.locale.Weekdays
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
551 ptc.shortWeekdays = ptc.locale.shortWeekdays
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
552 ptc.Months = ptc.locale.Months
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
553 ptc.shortMonths = ptc.locale.shortMonths
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
554 ptc.dateFormats = ptc.locale.dateFormats
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
555 ptc.timeFormats = ptc.locale.timeFormats
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
556
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
557 # these values are used to setup the various bits
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
558 # of the regex values used to parse
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
559 #
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
560 # check if a local set of constants has been
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
561 # provided, if not use en_US as the default
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
562 if ptc.localeID in pdtLocales:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
563 ptc.re_sources = pdtLocales[ptc.localeID].re_sources
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
564 ptc.re_values = pdtLocales[ptc.localeID].re_consts
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
565
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
566 units = pdtLocales[ptc.localeID].units
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
567
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
568 ptc.Modifiers = pdtLocales[ptc.localeID].modifiers
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
569 ptc.dayOffsets = pdtLocales[ptc.localeID].dayoffsets
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
570
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
571 # for now, pull over any missing keys from the US set
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
572 for key in pdtLocales['en_US'].re_consts:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
573 if not key in ptc.re_values:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
574 ptc.re_values[key] = pdtLocales['en_US'].re_consts[key]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
575 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
576 ptc.re_sources = pdtLocales['en_US'].re_sources
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
577 ptc.re_values = pdtLocales['en_US'].re_consts
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
578 ptc.Modifiers = pdtLocales['en_US'].modifiers
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
579 ptc.dayOffsets = pdtLocales['en_US'].dayoffsets
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
580 units = pdtLocales['en_US'].units
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
581
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
582 # escape any regex special characters that may be found
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
583 wd = tuple(map(re.escape, ptc.Weekdays))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
584 swd = tuple(map(re.escape, ptc.shortWeekdays))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
585 mth = tuple(map(re.escape, ptc.Months))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
586 smth = tuple(map(re.escape, ptc.shortMonths))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
587
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
588 ptc.re_values['months'] = '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' % mth
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
589 ptc.re_values['shortmonths'] = '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' % smth
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
590 ptc.re_values['days'] = '%s|%s|%s|%s|%s|%s|%s' % wd
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
591 ptc.re_values['shortdays'] = '%s|%s|%s|%s|%s|%s|%s' % swd
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
592
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
593 l = []
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
594 for unit in units:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
595 l.append('|'.join(units[unit]))
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
596
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
597 ptc.re_values['units'] = '|'.join(l)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
598 ptc.Units = ptc.re_values['units'].split('|')
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
599
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
600
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
601 def _initSymbols(ptc):
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
602 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
603 Helper function to initialize the single character constants
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
604 and other symbols needed.
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
605 """
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
606 ptc.timeSep = [ u':' ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
607 ptc.dateSep = [ u'/' ]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
608 ptc.meridian = [ u'AM', u'PM' ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
609
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
610 ptc.usesMeridian = True
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
611 ptc.uses24 = False
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
612
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
613 if pyicu and ptc.usePyICU:
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
614 am = u''
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
615 pm = u''
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
616 ts = ''
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
617
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
618 # ICU doesn't seem to provide directly the
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
619 # date or time seperator - so we have to
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
620 # figure it out
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
621 o = ptc.icu_tf['short']
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
622 s = ptc.timeFormats['short']
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
623
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
624 ptc.usesMeridian = u'a' in s
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
625 ptc.uses24 = u'H' in s
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
626
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
627 # '11:45 AM' or '11:45'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
628 s = o.format(datetime.datetime(2003, 10, 30, 11, 45))
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
629
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
630 # ': AM' or ':'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
631 s = s.replace('11', '').replace('45', '')
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
632
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
633 if len(s) > 0:
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
634 ts = s[0]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
635
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
636 if ptc.usesMeridian:
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
637 # '23:45 AM' or '23:45'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
638 am = s[1:].strip()
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
639 s = o.format(datetime.datetime(2003, 10, 30, 23, 45))
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
640
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
641 if ptc.uses24:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
642 s = s.replace('23', '')
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
643 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
644 s = s.replace('11', '')
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
645
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
646 # 'PM' or ''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
647 pm = s.replace('45', '').replace(ts, '').strip()
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
648
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
649 ptc.timeSep = [ ts ]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
650 ptc.meridian = [ am, pm ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
651
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
652 o = ptc.icu_df['short']
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
653 s = o.format(datetime.datetime(2003, 10, 30, 11, 45))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
654 s = s.replace('10', '').replace('30', '').replace('03', '').replace('2003', '')
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
655
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
656 if len(s) > 0:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
657 ds = s[0]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
658 else:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
659 ds = '/'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
660
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
661 ptc.dateSep = [ ds ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
662 s = ptc.dateFormats['short']
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
663 l = s.lower().split(ds)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
664 dp_order = []
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
665
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
666 for s in l:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
667 if len(s) > 0:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
668 dp_order.append(s[:1])
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
669
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
670 ptc.dp_order = dp_order
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
671 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
672 ptc.timeSep = ptc.locale.timeSep
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
673 ptc.dateSep = ptc.locale.dateSep
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
674 ptc.meridian = ptc.locale.meridian
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
675 ptc.usesMeridian = ptc.locale.usesMeridian
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
676 ptc.uses24 = ptc.locale.uses24
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
677 ptc.dp_order = ptc.locale.dp_order
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
678
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
679 # build am and pm lists to contain
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
680 # original case, lowercase and first-char
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
681 # versions of the meridian text
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
682
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
683 if len(ptc.meridian) > 0:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
684 am = ptc.meridian[0]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
685 ptc.am = [ am ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
686
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
687 if len(am) > 0:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
688 ptc.am.append(am[0])
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
689 am = am.lower()
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
690 ptc.am.append(am)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
691 ptc.am.append(am[0])
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
692 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
693 am = ''
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
694 ptc.am = [ '', '' ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
695
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
696 if len(ptc.meridian) > 1:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
697 pm = ptc.meridian[1]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
698 ptc.pm = [ pm ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
699
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
700 if len(pm) > 0:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
701 ptc.pm.append(pm[0])
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
702 pm = pm.lower()
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
703 ptc.pm.append(pm)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
704 ptc.pm.append(pm[0])
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
705 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
706 pm = ''
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
707 ptc.pm = [ '', '' ]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
708
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
709
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
710 def _initPatterns(ptc):
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
711 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
712 Helper function to take the different localized bits from ptc and
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
713 create the regex strings.
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
714 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
715 # TODO add code to parse the date formats and build the regexes up from sub-parts
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
716 # TODO find all hard-coded uses of date/time seperators
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
717
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
718 ptc.RE_DATE4 = r'''(?P<date>(((?P<day>\d\d?)(?P<suffix>%(daysuffix)s)?(,)?(\s)?)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
719 (?P<mthname>(%(months)s|%(shortmonths)s))\s?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
720 (?P<year>\d\d(\d\d)?)?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
721 )
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
722 )''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
723
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
724 # I refactored DATE3 to fix Issue 16 http://code.google.com/p/parsedatetime/issues/detail?id=16
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
725 # I suspect the final line was for a trailing time - but testing shows it's not needed
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
726 # ptc.RE_DATE3 = r'''(?P<date>((?P<mthname>(%(months)s|%(shortmonths)s))\s?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
727 # ((?P<day>\d\d?)(\s?|%(daysuffix)s|$)+)?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
728 # (,\s?(?P<year>\d\d(\d\d)?))?))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
729 # (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
730 ptc.RE_DATE3 = r'''(?P<date>(
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
731 (((?P<mthname>(%(months)s|%(shortmonths)s))|
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
732 ((?P<day>\d\d?)(?P<suffix>%(daysuffix)s)?))(\s)?){1,2}
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
733 ((,)?(\s)?(?P<year>\d\d(\d\d)?))?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
734 )
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
735 )''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
736 ptc.RE_MONTH = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
737 (?P<month>(
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
738 (?P<mthname>(%(months)s|%(shortmonths)s))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
739 (\s?(?P<year>(\d\d\d\d)))?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
740 ))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
741 (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
742 ptc.RE_WEEKDAY = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
743 (?P<weekday>(%(days)s|%(shortdays)s))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
744 (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
745
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
746 ptc.RE_SPECIAL = r'(?P<special>^[%(specials)s]+)\s+' % ptc.re_values
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
747 ptc.RE_UNITS = r'''(?P<qty>(-?\d+\s*
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
748 (?P<units>((%(units)s)s?))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
749 ))''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
750 ptc.RE_QUNITS = r'''(?P<qty>(-?\d+\s?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
751 (?P<qunits>%(qunits)s)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
752 (\s?|,|$)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
753 ))''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
754 ptc.RE_MODIFIER = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
755 (?P<modifier>
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
756 (previous|prev|last|next|eod|eo|(end\sof)|(in\sa)))''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
757 ptc.RE_MODIFIER2 = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
758 (?P<modifier>
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
759 (from|before|after|ago|prior))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
760 (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
761 ptc.RE_TIMEHMS = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
762 (?P<hours>\d\d?)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
763 (?P<tsep>%(timeseperator)s|)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
764 (?P<minutes>\d\d)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
765 (?:(?P=tsep)(?P<seconds>\d\d(?:[.,]\d+)?))?''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
766 ptc.RE_TIMEHMS2 = r'''(?P<hours>(\d\d?))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
767 ((?P<tsep>%(timeseperator)s|)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
768 (?P<minutes>(\d\d?))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
769 (?:(?P=tsep)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
770 (?P<seconds>\d\d?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
771 (?:[.,]\d+)?))?)?''' % ptc.re_values
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
772
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
773 if 'meridian' in ptc.re_values:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
774 ptc.RE_TIMEHMS2 += r'\s?(?P<meridian>(%(meridian)s))' % ptc.re_values
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
775
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
776 dateSeps = ''.join(ptc.dateSep) + '.'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
777
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
778 ptc.RE_DATE = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
779 (?P<date>(\d\d?[%s]\d\d?([%s]\d\d(\d\d)?)?))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
780 (\s?|$|[^0-9a-zA-Z])''' % (dateSeps, dateSeps)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
781 ptc.RE_DATE2 = r'[%s]' % dateSeps
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
782 ptc.RE_DAY = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
783 (?P<day>(today|tomorrow|yesterday))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
784 (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
785 ptc.RE_DAY2 = r'''(?P<day>\d\d?)|(?P<suffix>%(daysuffix)s)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
786 ''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
787 ptc.RE_TIME = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
788 (?P<time>(morning|breakfast|noon|lunch|evening|midnight|tonight|dinner|night|now))
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
789 (\s?|$|[^0-9a-zA-Z])''' % ptc.re_values
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
790 ptc.RE_REMAINING = r'\s+'
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
791
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
792 # Regex for date/time ranges
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
793 ptc.RE_RTIMEHMS = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
794 (\d\d?)%(timeseperator)s
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
795 (\d\d)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
796 (%(timeseperator)s(\d\d))?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
797 (\s?|$)''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
798 ptc.RE_RTIMEHMS2 = r'''(\s?|^)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
799 (\d\d?)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
800 (%(timeseperator)s(\d\d?))?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
801 (%(timeseperator)s(\d\d?))?''' % ptc.re_values
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
802
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
803 if 'meridian' in ptc.re_values:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
804 ptc.RE_RTIMEHMS2 += r'\s?(%(meridian)s)' % ptc.re_values
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
805
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
806 ptc.RE_RDATE = r'(\d+([%s]\d+)+)' % dateSeps
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
807 ptc.RE_RDATE3 = r'''((((%(months)s))\s?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
808 ((\d\d?)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
809 (\s?|%(daysuffix)s|$)+)?
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
810 (,\s?\d\d\d\d)?))''' % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
811
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
812 # "06/07/06 - 08/09/06"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
813 ptc.DATERNG1 = ptc.RE_RDATE + r'\s?%(rangeseperator)s\s?' + ptc.RE_RDATE
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
814 ptc.DATERNG1 = ptc.DATERNG1 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
815
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
816 # "march 31 - june 1st, 2006"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
817 ptc.DATERNG2 = ptc.RE_RDATE3 + r'\s?%(rangeseperator)s\s?' + ptc.RE_RDATE3
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
818 ptc.DATERNG2 = ptc.DATERNG2 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
819
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
820 # "march 1rd -13th"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
821 ptc.DATERNG3 = ptc.RE_RDATE3 + r'\s?%(rangeseperator)s\s?(\d\d?)\s?(rd|st|nd|th)?'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
822 ptc.DATERNG3 = ptc.DATERNG3 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
823
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
824 # "4:00:55 pm - 5:90:44 am", '4p-5p'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
825 ptc.TIMERNG1 = ptc.RE_RTIMEHMS2 + r'\s?%(rangeseperator)s\s?' + ptc.RE_RTIMEHMS2
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
826 ptc.TIMERNG1 = ptc.TIMERNG1 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
827
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
828 # "4:00 - 5:90 ", "4:55:55-3:44:55"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
829 ptc.TIMERNG2 = ptc.RE_RTIMEHMS + r'\s?%(rangeseperator)s\s?' + ptc.RE_RTIMEHMS
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
830 ptc.TIMERNG2 = ptc.TIMERNG2 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
831
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
832 # "4-5pm "
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
833 ptc.TIMERNG3 = r'\d\d?\s?%(rangeseperator)s\s?' + ptc.RE_RTIMEHMS2
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
834 ptc.TIMERNG3 = ptc.TIMERNG3 % ptc.re_values
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
835
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
836 # "4:30-5pm "
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
837 ptc.TIMERNG4 = ptc.RE_RTIMEHMS + r'\s?%(rangeseperator)s\s?' + ptc.RE_RTIMEHMS2
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
838 ptc.TIMERNG4 = ptc.TIMERNG4 % ptc.re_values
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
839
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
840
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
841 def _initConstants(ptc):
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
842 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
843 Create localized versions of the units, week and month names
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
844 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
845 # build weekday offsets - yes, it assumes the Weekday and shortWeekday
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
846 # lists are in the same order and Mon..Sun (Python style)
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
847 ptc.WeekdayOffsets = {}
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
848
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
849 o = 0
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
850 for key in ptc.Weekdays:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
851 ptc.WeekdayOffsets[key] = o
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
852 o += 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
853 o = 0
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
854 for key in ptc.shortWeekdays:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
855 ptc.WeekdayOffsets[key] = o
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
856 o += 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
857
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
858 # build month offsets - yes, it assumes the Months and shortMonths
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
859 # lists are in the same order and Jan..Dec
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
860 ptc.MonthOffsets = {}
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
861
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
862 o = 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
863 for key in ptc.Months:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
864 ptc.MonthOffsets[key] = o
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
865 o += 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
866 o = 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
867 for key in ptc.shortMonths:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
868 ptc.MonthOffsets[key] = o
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
869 o += 1
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
870
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
871 # ptc.DaySuffixes = ptc.re_consts['daysuffix'].split('|')
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
872
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
873
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
874 class Constants:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
875 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
876 Default set of constants for parsedatetime.
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
877
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
878 If PyICU is present, then the class will first try to get PyICU
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
879 to return a locale specified by C{localeID}. If either C{localeID} is
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
880 None or if the locale does not exist within PyICU, then each of the
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
881 locales defined in C{fallbackLocales} is tried in order.
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
882
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
883 If PyICU is not present or none of the specified locales can be used,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
884 then the class will initialize itself to the en_US locale.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
885
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
886 if PyICU is not present or not requested, only the locales defined by
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
887 C{pdtLocales} will be searched.
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
888 """
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
889 def __init__(self, localeID=None, usePyICU=True, fallbackLocales=['en_US']):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
890 self.localeID = localeID
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
891 self.fallbackLocales = fallbackLocales
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
892
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
893 if 'en_US' not in self.fallbackLocales:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
894 self.fallbackLocales.append('en_US')
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
895
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
896 # define non-locale specific constants
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
897
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
898 self.locale = None
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
899 self.usePyICU = usePyICU
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
900
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
901 # starting cache of leap years
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
902 # daysInMonth will add to this if during
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
903 # runtime it gets a request for a year not found
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
904 self._leapYears = [ 1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
905 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
906 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
907 2036, 2040, 2044, 2048, 2052, 2056, 2060, 2064, 2068, 2072, 2076,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
908 2080, 2084, 2088, 2092, 2096 ]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
909
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
910 self.Second = 1
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
911 self.Minute = 60 * self.Second
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
912 self.Hour = 60 * self.Minute
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
913 self.Day = 24 * self.Hour
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
914 self.Week = 7 * self.Day
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
915 self.Month = 30 * self.Day
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
916 self.Year = 365 * self.Day
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
917
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
918 self.rangeSep = u'-'
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
919
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
920 self._DaysInMonthList = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
921
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
922 self.BirthdayEpoch = 50
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
923
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
924 # DOWParseStyle controls how we parse "Tuesday"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
925 # If the current day was Thursday and the text to parse is "Tuesday"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
926 # then the following table shows how each style would be returned
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
927 # -1, 0, +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
928 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
929 # Current day marked as ***
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
930 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
931 # Sun Mon Tue Wed Thu Fri Sat
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
932 # week -1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
933 # current -1,0 ***
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
934 # week +1 +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
935 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
936 # If the current day was Monday and the text to parse is "Tuesday"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
937 # then the following table shows how each style would be returned
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
938 # -1, 0, +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
939 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
940 # Sun Mon Tue Wed Thu Fri Sat
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
941 # week -1 -1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
942 # current *** 0,+1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
943 # week +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
944
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
945 self.DOWParseStyle = 1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
946
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
947 # CurrentDOWParseStyle controls how we parse "Friday"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
948 # If the current day was Friday and the text to parse is "Friday"
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
949 # then the following table shows how each style would be returned
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
950 # True/False. This also depends on DOWParseStyle.
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
951 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
952 # Current day marked as ***
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
953 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
954 # DOWParseStyle = 0
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
955 # Sun Mon Tue Wed Thu Fri Sat
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
956 # week -1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
957 # current T,F
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
958 # week +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
959 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
960 # DOWParseStyle = -1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
961 # Sun Mon Tue Wed Thu Fri Sat
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
962 # week -1 F
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
963 # current T
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
964 # week +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
965 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
966 # DOWParseStyle = +1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
967 #
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
968 # Sun Mon Tue Wed Thu Fri Sat
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
969 # week -1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
970 # current T
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
971 # week +1 F
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
972
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
973 self.CurrentDOWParseStyle = False
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
974
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
975 # initalize attributes to empty values to ensure
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
976 # they are defined
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
977 self.re_sources = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
978 self.re_values = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
979 self.Modifiers = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
980 self.dayOffsets = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
981 self.WeekdayOffsets = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
982 self.MonthOffsets = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
983 self.dateSep = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
984 self.timeSep = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
985 self.am = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
986 self.pm = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
987 self.meridian = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
988 self.usesMeridian = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
989 self.uses24 = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
990 self.dp_order = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
991
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
992 self.RE_DATE4 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
993 self.RE_DATE3 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
994 self.RE_MONTH = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
995 self.RE_WEEKDAY = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
996 self.RE_SPECIAL = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
997 self.RE_UNITS = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
998 self.RE_QUNITS = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
999 self.RE_MODIFIER = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1000 self.RE_MODIFIER2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1001 self.RE_TIMEHMS = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1002 self.RE_TIMEHMS2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1003 self.RE_DATE = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1004 self.RE_DATE2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1005 self.RE_DAY = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1006 self.RE_DAY2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1007 self.RE_TIME = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1008 self.RE_REMAINING = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1009 self.RE_RTIMEHMS = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1010 self.RE_RTIMEHMS2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1011 self.RE_RDATE = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1012 self.RE_RDATE3 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1013 self.DATERNG1 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1014 self.DATERNG2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1015 self.DATERNG3 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1016 self.TIMERNG1 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1017 self.TIMERNG2 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1018 self.TIMERNG3 = r''
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1019 self.TIMERNG4 = r''
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1020
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1021 _initLocale(self)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1022 _initConstants(self)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1023 _initSymbols(self)
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1024 _initPatterns(self)
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1025
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1026 self.re_option = re.IGNORECASE + re.VERBOSE
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1027 self.cre_source = { 'CRE_SPECIAL': self.RE_SPECIAL,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1028 'CRE_UNITS': self.RE_UNITS,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1029 'CRE_QUNITS': self.RE_QUNITS,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1030 'CRE_MODIFIER': self.RE_MODIFIER,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1031 'CRE_MODIFIER2': self.RE_MODIFIER2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1032 'CRE_TIMEHMS': self.RE_TIMEHMS,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1033 'CRE_TIMEHMS2': self.RE_TIMEHMS2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1034 'CRE_DATE': self.RE_DATE,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1035 'CRE_DATE2': self.RE_DATE2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1036 'CRE_DATE3': self.RE_DATE3,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1037 'CRE_DATE4': self.RE_DATE4,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1038 'CRE_MONTH': self.RE_MONTH,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1039 'CRE_WEEKDAY': self.RE_WEEKDAY,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1040 'CRE_DAY': self.RE_DAY,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1041 'CRE_DAY2': self.RE_DAY2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1042 'CRE_TIME': self.RE_TIME,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1043 'CRE_REMAINING': self.RE_REMAINING,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1044 'CRE_RTIMEHMS': self.RE_RTIMEHMS,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1045 'CRE_RTIMEHMS2': self.RE_RTIMEHMS2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1046 'CRE_RDATE': self.RE_RDATE,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1047 'CRE_RDATE3': self.RE_RDATE3,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1048 'CRE_TIMERNG1': self.TIMERNG1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1049 'CRE_TIMERNG2': self.TIMERNG2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1050 'CRE_TIMERNG3': self.TIMERNG3,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1051 'CRE_TIMERNG4': self.TIMERNG4,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1052 'CRE_DATERNG1': self.DATERNG1,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1053 'CRE_DATERNG2': self.DATERNG2,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1054 'CRE_DATERNG3': self.DATERNG3,
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1055 }
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1056 self.cre_keys = self.cre_source.keys()
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1057
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1058
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1059 def __getattr__(self, name):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1060 if name in self.cre_keys:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1061 value = re.compile(self.cre_source[name], self.re_option)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1062 setattr(self, name, value)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1063 return value
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1064 else:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1065 raise AttributeError, name
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1066
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1067 def daysInMonth(self, month, year):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1068 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1069 Take the given month (1-12) and a given year (4 digit) return
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1070 the number of days in the month adjusting for leap year as needed
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1071 """
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1072 result = None
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1073
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1074 if month > 0 and month <= 12:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1075 result = self._DaysInMonthList[month - 1]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1076
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1077 if month == 2:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1078 if year in self._leapYears:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1079 result += 1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1080 else:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1081 if calendar.isleap(year):
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1082 self._leapYears.append(year)
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1083 result += 1
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1084
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1085 return result
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1086
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1087 def buildSources(self, sourceTime=None):
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1088 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1089 Return a dictionary of date/time tuples based on the keys
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1090 found in self.re_sources.
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1091
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1092 The current time is used as the default and any specified
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1093 item found in self.re_sources is inserted into the value
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1094 and the generated dictionary is returned.
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1095 """
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1096 if sourceTime is None:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1097 (yr, mth, dy, hr, mn, sec, wd, yd, isdst) = time.localtime()
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1098 else:
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1099 (yr, mth, dy, hr, mn, sec, wd, yd, isdst) = sourceTime
1433
6b0ea72d7665 mtime search works, added MoinMoin.support.parsedatetime, small fixes
Franz Pletz <fpletz AT franz-pletz DOT org>
parents:
diff changeset
1100
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1101 sources = {}
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1102 defaults = { 'yr': yr, 'mth': mth, 'dy': dy,
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1103 'hr': hr, 'mn': mn, 'sec': sec, }
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1104
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1105 for item in self.re_sources:
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1106 values = {}
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1107 source = self.re_sources[item]
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1108
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1109 for key in defaults.keys():
5185
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1110 if key in source:
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1111 values[key] = source[key]
0a6fe22644e3 updated parsedatetime to 0.8.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4327
diff changeset
1112 else:
1463
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1113 values[key] = defaults[key]
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1114
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1115 sources[item] = ( values['yr'], values['mth'], values['dy'],
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1116 values['hr'], values['mn'], values['sec'], wd, yd, isdst )
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1117
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1118 return sources
446e20f5005c update parsedatetime to 0.7
Franz Pletz <fpletz AT franz-pletz DOT org>
parents: 1433
diff changeset
1119