Class which handles what inputs are accepted. Subclass this to customize the language and acceptable values for each parameter. :param dayfirst: Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (``True``) or month (``False``
| 239 | |
| 240 | |
| 241 | class parserinfo(object): |
| 242 | """ |
| 243 | Class which handles what inputs are accepted. Subclass this to customize |
| 244 | the language and acceptable values for each parameter. |
| 245 | |
| 246 | :param dayfirst: |
| 247 | Whether to interpret the first value in an ambiguous 3-integer date |
| 248 | (e.g. 01/05/09) as the day (``True``) or month (``False``). If |
| 249 | ``yearfirst`` is set to ``True``, this distinguishes between YDM |
| 250 | and YMD. Default is ``False``. |
| 251 | |
| 252 | :param yearfirst: |
| 253 | Whether to interpret the first value in an ambiguous 3-integer date |
| 254 | (e.g. 01/05/09) as the year. If ``True``, the first number is taken |
| 255 | to be the year, otherwise the last number is taken to be the year. |
| 256 | Default is ``False``. |
| 257 | """ |
| 258 | |
| 259 | # m from a.m/p.m, t from ISO T separator |
| 260 | JUMP = [" ", ".", ",", ";", "-", "/", "'", |
| 261 | "at", "on", "and", "ad", "m", "t", "of", |
| 262 | "st", "nd", "rd", "th"] |
| 263 | |
| 264 | WEEKDAYS = [("Mon", "Monday"), |
| 265 | ("Tue", "Tuesday"), # TODO: "Tues" |
| 266 | ("Wed", "Wednesday"), |
| 267 | ("Thu", "Thursday"), # TODO: "Thurs" |
| 268 | ("Fri", "Friday"), |
| 269 | ("Sat", "Saturday"), |
| 270 | ("Sun", "Sunday")] |
| 271 | MONTHS = [("Jan", "January"), |
| 272 | ("Feb", "February"), # TODO: "Febr" |
| 273 | ("Mar", "March"), |
| 274 | ("Apr", "April"), |
| 275 | ("May", "May"), |
| 276 | ("Jun", "June"), |
| 277 | ("Jul", "July"), |
| 278 | ("Aug", "August"), |
| 279 | ("Sep", "Sept", "September"), |
| 280 | ("Oct", "October"), |
| 281 | ("Nov", "November"), |
| 282 | ("Dec", "December")] |
| 283 | HMS = [("h", "hour", "hours"), |
| 284 | ("m", "minute", "minutes"), |
| 285 | ("s", "second", "seconds")] |
| 286 | AMPM = [("am", "a"), |
| 287 | ("pm", "p")] |
| 288 | UTCZONE = ["UTC", "GMT", "Z", "z"] |
| 289 | PERTAIN = ["of"] |
| 290 | TZOFFSET = {} |
| 291 | # TODO: ERA = ["AD", "BC", "CE", "BCE", "Stardate", |
| 292 | # "Anno Domini", "Year of Our Lord"] |
| 293 | |
| 294 | def __init__(self, dayfirst=False, yearfirst=False): |
| 295 | self._jump = self._convert(self.JUMP) |
| 296 | self._weekdays = self._convert(self.WEEKDAYS) |
| 297 | self._months = self._convert(self.MONTHS) |
| 298 | self._hms = self._convert(self.HMS) |
no outgoing calls