Package parsedatetime :: Module parsedatetime_consts
[hide private]
[frames] | no frames]

Source Code for Module parsedatetime.parsedatetime_consts

   1  #!/usr/bin/env python 
   2   
   3  """ 
   4  parsedatetime constants and helper functions to determine 
   5  regex values from Locale information if present. 
   6   
   7  Also contains the internal Locale classes to give some sane 
   8  defaults if PyICU is not found. 
   9  """ 
  10   
  11  __license__ = """ 
  12  Copyright (c) 2004-2008 Mike Taylor 
  13  Copyright (c) 2006-2008 Darshana Chhajed 
  14  Copyright (c)      2007 Bernd Zeimetz <bzed@debian.org> 
  15  All rights reserved. 
  16   
  17  Licensed under the Apache License, Version 2.0 (the "License"); 
  18  you may not use this file except in compliance with the License. 
  19  You may obtain a copy of the License at 
  20   
  21     http://www.apache.org/licenses/LICENSE-2.0 
  22   
  23  Unless required by applicable law or agreed to in writing, software 
  24  distributed under the License is distributed on an "AS IS" BASIS, 
  25  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  26  See the License for the specific language governing permissions and 
  27  limitations under the License. 
  28  """ 
  29   
  30  try: 
  31      import PyICU as pyicu 
  32  except: 
  33      pyicu = None 
  34   
  35   
  36  import datetime 
  37  import calendar 
  38  import time 
  39  import re 
  40   
  41   
42 -class pdtLocale_en:
43 """ 44 en_US Locale constants 45 46 This class will be used to initialize L{Constants} if PyICU is not located. 47 48 Defined as class variables are the lists and strings needed by parsedatetime 49 to evaluate strings for USA 50 """ 51 52 localeID = 'en_US' # don't use a unicode string 53 dateSep = [ u'/', u'.' ] 54 timeSep = [ u':' ] 55 meridian = [ u'AM', u'PM' ] 56 usesMeridian = True 57 uses24 = False 58 59 Weekdays = [ u'monday', u'tuesday', u'wednesday', 60 u'thursday', u'friday', u'saturday', u'sunday', 61 ] 62 shortWeekdays = [ u'mon', u'tues', u'wed', 63 u'thu', u'fri', u'sat', u'sun', 64 ] 65 Months = [ u'january', u'february', u'march', 66 u'april', u'may', u'june', 67 u'july', u'august', u'september', 68 u'october', u'november', u'december', 69 ] 70 shortMonths = [ u'jan', u'feb', u'mar', 71 u'apr', u'may', u'jun', 72 u'jul', u'aug', u'sep', 73 u'oct', u'nov', u'dec', 74 ] 75 dateFormats = { 'full': 'EEEE, MMMM d, yyyy', 76 'long': 'MMMM d, yyyy', 77 'medium': 'MMM d, yyyy', 78 'short': 'M/d/yy', 79 } 80 timeFormats = { 'full': 'h:mm:ss a z', 81 'long': 'h:mm:ss a z', 82 'medium': 'h:mm:ss a', 83 'short': 'h:mm a', 84 } 85 86 dp_order = [ u'm', u'd', u'y' ] 87 88 # this will be added to re_consts later 89 units = { 'seconds': [ 'second', 'sec' ], 90 'minutes': [ 'minute', 'min' ], 91 'hours': [ 'hour', 'hr' ], 92 'days': [ 'day', 'dy' ], 93 'weeks': [ 'week', 'wk' ], 94 'months': [ 'month', 'mth' ], 95 'years': [ 'year', 'yr' ], 96 } 97 98 # text constants to be used by regex's later 99 re_consts = { 'specials': 'in|on|of|at', 100 'timeseperator': ':', 101 'rangeseperator': '-', 102 'daysuffix': 'rd|st|nd|th', 103 'meridian': 'am|pm|a.m.|p.m.|a|p', 104 'qunits': 'h|m|s|d|w|m|y', 105 'now': [ 'now' ], 106 } 107 108 # Used to adjust the returned date before/after the source 109 modifiers = { 'from': 1, 110 'before': -1, 111 'after': 1, 112 'ago': -1, 113 'prior': -1, 114 'prev': -1, 115 'last': -1, 116 'next': 1, 117 'previous': -1, 118 'in a': 2, 119 'end of': 0, 120 'eod': 0, 121 'eo': 0 122 } 123 124 dayoffsets = { 'tomorrow': 1, 125 'today': 0, 126 'yesterday': -1, 127 } 128 129 # special day and/or times, i.e. lunch, noon, evening 130 # each element in the dictionary is a dictionary that is used 131 # to fill in any value to be replace - the current date/time will 132 # already have been populated by the method buildSources 133 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 }, 134 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 }, 135 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 }, 136 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 }, 137 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 }, 138 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 }, 139 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 }, 140 'night': { 'hr': 21, 'mn': 0, 'sec': 0 }, 141 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 }, 142 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 }, 143 }
144 145
146 -class pdtLocale_au:
147 """ 148 en_AU Locale constants 149 150 This class will be used to initialize L{Constants} if PyICU is not located. 151 152 Defined as class variables are the lists and strings needed by parsedatetime 153 to evaluate strings for Australia 154 """ 155 156 localeID = 'en_AU' # don't use a unicode string 157 dateSep = [ u'-', u'/' ] 158 timeSep = [ u':' ] 159 meridian = [ u'AM', u'PM' ] 160 usesMeridian = True 161 uses24 = False 162 163 Weekdays = [ u'monday', u'tuesday', u'wednesday', 164 u'thursday', u'friday', u'saturday', u'sunday', 165 ] 166 shortWeekdays = [ u'mon', u'tues', u'wed', 167 u'thu', u'fri', u'sat', u'sun', 168 ] 169 Months = [ u'january', u'february', u'march', 170 u'april', u'may', u'june', 171 u'july', u'august', u'september', 172 u'october', u'november', u'december', 173 ] 174 shortMonths = [ u'jan', u'feb', u'mar', 175 u'apr', u'may', u'jun', 176 u'jul', u'aug', u'sep', 177 u'oct', u'nov', u'dec', 178 ] 179 dateFormats = { 'full': 'EEEE, d MMMM yyyy', 180 'long': 'd MMMM yyyy', 181 'medium': 'dd/MM/yyyy', 182 'short': 'd/MM/yy', 183 } 184 timeFormats = { 'full': 'h:mm:ss a z', 185 'long': 'h:mm:ss a', 186 'medium': 'h:mm:ss a', 187 'short': 'h:mm a', 188 } 189 190 dp_order = [ u'd', u'm', u'y' ] 191 192 # this will be added to re_consts later 193 units = { 'seconds': [ 'second', 'sec' ], 194 'minutes': [ 'minute', 'min' ], 195 'hours': [ 'hour', 'hr' ], 196 'days': [ 'day', 'dy' ], 197 'weeks': [ 'week', 'wk' ], 198 'months': [ 'month', 'mth' ], 199 'years': [ 'year', 'yr' ], 200 } 201 202 # text constants to be used by regex's later 203 re_consts = { 'specials': 'in|on|of|at', 204 'timeseperator': ':', 205 'rangeseperator': '-', 206 'daysuffix': 'rd|st|nd|th', 207 'meridian': 'am|pm|a.m.|p.m.|a|p', 208 'qunits': 'h|m|s|d|w|m|y', 209 'now': [ 'now' ], 210 } 211 212 # Used to adjust the returned date before/after the source 213 modifiers = { 'from': 1, 214 'before': -1, 215 'after': 1, 216 'ago': 1, 217 'prior': -1, 218 'prev': -1, 219 'last': -1, 220 'next': 1, 221 'previous': -1, 222 'in a': 2, 223 'end of': 0, 224 'eo': 0, 225 } 226 227 dayoffsets = { 'tomorrow': 1, 228 'today': 0, 229 'yesterday': -1, 230 } 231 232 # special day and/or times, i.e. lunch, noon, evening 233 # each element in the dictionary is a dictionary that is used 234 # to fill in any value to be replace - the current date/time will 235 # already have been populated by the method buildSources 236 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 }, 237 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 }, 238 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 }, 239 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 }, 240 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 }, 241 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 }, 242 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 }, 243 'night': { 'hr': 21, 'mn': 0, 'sec': 0 }, 244 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 }, 245 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 }, 246 }
247 248
249 -class pdtLocale_es:
250 """ 251 es Locale constants 252 253 This class will be used to initialize L{Constants} if PyICU is not located. 254 255 Defined as class variables are the lists and strings needed by parsedatetime 256 to evaluate strings in Spanish 257 258 Note that I don't speak Spanish so many of the items below are still in English 259 """ 260 261 localeID = 'es' # don't use a unicode string 262 dateSep = [ u'/' ] 263 timeSep = [ u':' ] 264 meridian = [] 265 usesMeridian = False 266 uses24 = True 267 268 Weekdays = [ u'lunes', u'martes', u'mi\xe9rcoles', 269 u'jueves', u'viernes', u's\xe1bado', u'domingo', 270 ] 271 shortWeekdays = [ u'lun', u'mar', u'mi\xe9', 272 u'jue', u'vie', u's\xe1b', u'dom', 273 ] 274 Months = [ u'enero', u'febrero', u'marzo', 275 u'abril', u'mayo', u'junio', 276 u'julio', u'agosto', u'septiembre', 277 u'octubre', u'noviembre', u'diciembre' 278 ] 279 shortMonths = [ u'ene', u'feb', u'mar', 280 u'abr', u'may', u'jun', 281 u'jul', u'ago', u'sep', 282 u'oct', u'nov', u'dic' 283 ] 284 dateFormats = { 'full': "EEEE d' de 'MMMM' de 'yyyy", 285 'long': "d' de 'MMMM' de 'yyyy", 286 'medium': "dd-MMM-yy", 287 'short': "d/MM/yy", 288 } 289 timeFormats = { 'full': "HH'H'mm' 'ss z", 290 'long': "HH:mm:ss z", 291 'medium': "HH:mm:ss", 292 'short': "HH:mm", 293 } 294 295 dp_order = [ u'd', u'm', u'y' ] 296 297 # this will be added to re_consts later 298 units = { 'seconds': [ 'second', 'sec' ], 299 'minutes': [ 'minute', 'min' ], 300 'hours': [ 'hour', 'hr' ], 301 'days': [ 'day', 'dy' ], 302 'weeks': [ 'week', 'wk' ], 303 'months': [ 'month', 'mth' ], 304 'years': [ 'year', 'yr' ], 305 } 306 307 # text constants to be used by regex's later 308 re_consts = { 'specials': 'in|on|of|at', 309 'timeseperator': timeSep, 310 'dateseperator': dateSep, 311 'rangeseperator': '-', 312 'daysuffix': 'rd|st|nd|th', 313 'qunits': 'h|m|s|d|w|m|y', 314 'now': [ 'now' ], 315 } 316 317 # Used to adjust the returned date before/after the source 318 modifiers = { 'from': 1, 319 'before': -1, 320 'after': 1, 321 'ago': 1, 322 'prior': -1, 323 'prev': -1, 324 'last': -1, 325 'next': 1, 326 'previous': -1, 327 'in a': 2, 328 'end of': 0, 329 'eo': 0, 330 } 331 332 dayoffsets = { 'tomorrow': 1, 333 'today': 0, 334 'yesterday': -1, 335 } 336 337 # special day and/or times, i.e. lunch, noon, evening 338 # each element in the dictionary is a dictionary that is used 339 # to fill in any value to be replace - the current date/time will 340 # already have been populated by the method buildSources 341 re_sources = { 'noon': { 'hr': 12, 'mn': 0, 'sec': 0 }, 342 'lunch': { 'hr': 12, 'mn': 0, 'sec': 0 }, 343 'morning': { 'hr': 6, 'mn': 0, 'sec': 0 }, 344 'breakfast': { 'hr': 8, 'mn': 0, 'sec': 0 }, 345 'dinner': { 'hr': 19, 'mn': 0, 'sec': 0 }, 346 'evening': { 'hr': 18, 'mn': 0, 'sec': 0 }, 347 'midnight': { 'hr': 0, 'mn': 0, 'sec': 0 }, 348 'night': { 'hr': 21, 'mn': 0, 'sec': 0 }, 349 'tonight': { 'hr': 21, 'mn': 0, 'sec': 0 }, 350 'eod': { 'hr': 17, 'mn': 0, 'sec': 0 }, 351 }
352 353
354 -class pdtLocale_de:
355 """ 356 de_DE Locale constants 357 358 This class will be used to initialize L{Constants} if PyICU is not located. 359 360 Contributed by Debian parsedatetime package maintainer Bernd Zeimetz <bzed@debian.org> 361 362 Defined as class variables are the lists and strings needed by parsedatetime 363 to evaluate strings for German 364 """ 365 366 localeID = 'de_DE' # don't use a unicode string 367 dateSep = [ u'.' ] 368 timeSep = [ u':' ] 369 meridian = [ ] 370 usesMeridian = False 371 uses24 = True 372 373 Weekdays = [ u'montag', u'dienstag', u'mittwoch', 374 u'donnerstag', u'freitag', u'samstag', u'sonntag', 375 ] 376 shortWeekdays = [ u'mo', u'di', u'mi', 377 u'do', u'fr', u'sa', u'so', 378 ] 379 Months = [ u'januar', u'februar', u'm\xe4rz', 380 u'april', u'mai', u'juni', 381 u'juli', u'august', u'september', 382 u'oktober', u'november', u'dezember', 383 ] 384 shortMonths = [ u'jan', u'feb', u'mrz', 385 u'apr', u'mai', u'jun', 386 u'jul', u'aug', u'sep', 387 u'okt', u'nov', u'dez', 388 ] 389 dateFormats = { 'full': u'EEEE, d. MMMM yyyy', 390 'long': u'd. MMMM yyyy', 391 'medium': u'dd.MM.yyyy', 392 'short': u'dd.MM.yy' 393 } 394 395 timeFormats = { 'full': u'HH:mm:ss v', 396 'long': u'HH:mm:ss z', 397 'medium': u'HH:mm:ss', 398 'short': u'HH:mm' 399 } 400 401 dp_order = [ u'd', u'm', u'y' ] 402 403 # this will be added to re_consts later 404 units = { 'seconds': [ 'sekunden', 'sek', 's' ], 405 'minutes': [ 'minuten', 'min' , 'm' ],