How to use the parsedatetime.parsedatetime.Calendar 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 dsoprea / PySchedules / pyschedules / examples / read.py View on Github external
from pyschedules.retrieve import parse_schedules

num_args = len(sys.argv)

if num_args < 3:
    print("Please provide a username and password.")
    sys.exit()

username = sys.argv[1]
password = sys.argv[2]

utc_start = None
utc_stop = None

if num_args >= 5:
    utc_start = Calendar.parse(sys.argv[3])
    utc_stop = Calendar.parse(sys.argv[4])

class EntityTrigger(IEntityTrigger):
    __v_station     = False
    __v_lineup      = True
    __v_mapping     = False
    __v_schedule    = False
    __v_program     = False
    __v_crew_member = False
    __v_genre       = False

    def new_station(self, _id, callSign, name, affiliate, fccChannelNumber):
        """Callback run for each new station"""

        if self.__v_station:
            # [Station: 11440, WFLX, WFLX, Fox Affiliate, 29]
github mozilla / version-control-tools / hgext / pushlog / feed.py View on Github external
scmutil,
    templatefilters,
    templateutil,
)

sys.path.append(os.path.dirname(__file__))

with demandimport.deactivated():
    from parsedatetime import parsedatetime as pdt

xmlescape = templatefilters.xmlescape

testedwith = b'4.8 4.9 5.0 5.1 5.2 5.3'
minimumhgversion = b'4.8'

cal = pdt.Calendar()
PUSHES_PER_PAGE = 10


def addwebcommand(f, name):
    '''Adds `f` as a webcommand named `name`.'''
    setattr(hgwebcommands, name, f)
    hgwebcommands.__all__.append(pycompat.bytestr(name))


ATOM_MIMETYPE = b'application/atom+xml'


class QueryType:
    '''Enumeration of the different Pushlog query types'''
    DATE, CHANGESET, PUSHID, COUNT = range(4)
github nate-parrott / Flashlight / NaturalCommands / date_field.py View on Github external
def transform(text):
    import parsedatetime.parsedatetime as pdt
    import time
    import datetime
    c = pdt.Calendar()
    result, what = c.parse(text)
    dt = datetime.datetime( *result[:6] )
    resolution = 60 if what == 3 else 24 * 60 * 60
    return {"timestamp": time.mktime(dt.timetuple()), "resolution": resolution, "text": text}
github armet / python-armet / src / armet / resources / attributes.py View on Github external
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.')
github armet / python-armet / src / armet / resources / attributes.py View on Github external
def _try(value):
        try:
            # Attempt to use the dateutil library to parse.
            from dateutil.parser import parse
            return parse(value, fuzzy=False)

        except ValueError:
            # Not a strictly formatted date; return nothing.
            pass

        try:
            import parsedatetime.parsedatetime as pdt
            import parsedatetime.parsedatetime_consts as pdc
            c = pdc.Constants()
            c.BirthdayEpoch = 80
            p = pdt.Calendar(c)
            result = p.parse(value)
            if result[1] != 0:
                return datetime.fromtimestamp(mktime(result[0]))

        except NameError:
            # No magic date/time support
            pass
github idan / django-fuzzydt / fuzzydt / fields.py View on Github external
"""
        super(DateTimeField, self).clean(value)
        if value in EMPTY_VALUES:
            return None
        if isinstance(value, datetime.datetime):
            return value
        if isinstance(value, datetime.date):
            return datetime.datetime(value.year, value.month, value.day)
        if isinstance(value, list):
            # Input comes from a SplitDateTimeWidget, for example. So, it's two
            # components: date and time.
            if len(value) != 2:
                raise ValidationError(self.error_messages['invalid'])
            value = '%s %s' % tuple(value)

        c = Calendar()
        parsed = c.parse(value)
        if parsed[1] == 3:
            return datetime.date(*parsed[0][:6])
        raise ValidationError(self.error_messages['invalid'])
github vilmibm / done / done / Commands.py View on Github external
def run(command, options, args):
    """Run the requested command. args is either a list of descriptions or a list of strings to filter by"""

    if command == "backend":
        subprocess.call(("sqlite3", db_path))

    if command == "add":
        dp = pdt.Calendar()
        due = mktime(dp.parse(options.due)[0]) if options.due else None
        print "added tasks..."
        [Task(desc, due).add() for desc in args]
        return

    filters = args if len(args) else None
    rows    = Query(filters, options).find()
    tasks   = [Task(r["desc"], r["due"]) for r in rows]

    if command == "list":
        for t in tasks:
            print "\t *", t

    if command == "done":
        print "done with..."
        finished_tasks = []