How to use the parsedatetime.parsedatetime.Constants function in parsedatetime

To help you get started, we’ve selected a few parsedatetime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github itamaro / evernote-utils / PyEvernote / ImportEvernoteTemplate.py View on Github external
# remove the prefix from the title
        args.action_title = ' '.join(args.action_title.split()[1:])
    else:
        when_prefix = args.when or raw_input(
                      'Enter action when context (single digit): ').strip()
    if args.when and when_prefix <> args.when:
        # inconsistency! Go with the title..
        print 'Detected when-context inconsistency. Choosing', when_prefix
    if not when_prefix in '123456':
        raise RuntimeError('I don\'t like you (not in range 1..6)')
    # Get action context (from arguments, or ask user if not supplied).
    context = deduce_context(args.context)
    # Process reminder, if specified
    if args.reminder:
        import parsedatetime.parsedatetime as pdt
        cal = pdt.Calendar(pdt.Constants('he_IL', True))
        res_date, res_flag = cal.parse(args.reminder)
        if 1 == res_flag:
            # parsed as date - so use 9am as default time
            res_date = res_date[:3] + g_DefaultReminderTime + res_date[6:]
        if 0 == res_flag:
            # Not parsed at all
            print 'Failed parsing reminder date/time'
            args.action_title = 'FIX REMINDER %s' % (args.action_title)
            args.reminder = None
        else:
            # Convert reminder date/time object to UTC datetime string
            args.reminder = strftime('%Y%m%dT%H%M00Z',
                                     gmtime(mktime(res_date)))
    
    # Prepare template dictionary
    tmpl_params = {
github armet / python-armet / src / armet / resources / attributes.py View on Github external
# Value is nothing; return it.
            return value

        try:
            # Attempt to use the dateutil library to parse.
            return parse_datetime(value, fuzzy=False)

        except (ValueError, AttributeError):
            # Not a strictly formatted date; return nothing.
            pass

        try:
            # Attempt to magic a date out of it.
            # TODO: List this somewhere as an optional dep.
            from parsedatetime import parsedatetime as pdt
            c = pdt.Constants()
            c.BirthdayEpoch = 80  # TODO: Figure out what this is.
            p = pdt.Calendar(c)
            result = p.parse(value)
            if result[1] != 0:
                return datetime.datetime.fromtimestamp(mktime(result[0]))

        except (NameError, ImportError, TypeError):
            # No magical date/time support.
            pass

        # Couldn't figure out what we're dealing with.
        raise ValueError('Invalid date/time or in an invalid format.')