How to use the parsedatetime.VERSION_CONTEXT_STYLE 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 bear / parsedatetime / tests / TestContext.py View on Github external
def setUp(self):
        self.cal = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE)
        (self.yr, self.mth, self.dy, self.hr, self.mn,
         self.sec, self.wd, self.yd, self.isdst) = time.localtime()
github bear / parsedatetime / tests / TestDelta.py View on Github external
def setUp(self):
        self.cal = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE)
        self.source = (2017, 1, 1, 7, 1, 2, 6, 1, 1)
github Rapptz / RoboDanny / cogs / utils / time.py View on Github external
def __init__(self, argument, *, now=None):
        match = self.compiled.fullmatch(argument)
        if match is None or not match.group(0):
            raise commands.BadArgument('invalid time provided')

        data = { k: int(v) for k, v in match.groupdict(default=0).items() }
        now = now or datetime.datetime.utcnow()
        self.dt = now + relativedelta(**data)

    @classmethod
    async def convert(cls, ctx, argument):
        return cls(argument, now=ctx.message.created_at)

class HumanTime:
    calendar = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE)

    def __init__(self, argument, *, now=None):
        now = now or datetime.datetime.utcnow()
        dt, status = self.calendar.parseDT(argument, sourceTime=now)
        if not status.hasDateOrTime:
            raise commands.BadArgument('invalid time provided, try e.g. "tomorrow" or "3 days"')

        if not status.hasTime:
            # replace it with the current time
            dt = dt.replace(hour=now.hour, minute=now.minute, second=now.second, microsecond=now.microsecond)

        self.dt = dt
        self._past = dt < now

    @classmethod
    async def convert(cls, ctx, argument):
github wireservice / agate / agate / data_types / date.py View on Github external
def __setstate__(self, data):
        """
        Restore state from the unpickled state values. Set _parser to an instance
        of the parsedatetime Calendar class.
        """
        self.__dict__.update(data)
        self.parser = parsedatetime.Calendar(version=parsedatetime.VERSION_CONTEXT_STYLE)
github wireservice / agate / agate / data_types / date_time.py View on Github external
def __init__(self, datetime_format=None, timezone=None, **kwargs):
        super(DateTime, self).__init__(**kwargs)

        self.datetime_format = datetime_format
        self.timezone = timezone

        now = datetime.datetime.now()
        self._source_time = datetime.datetime(
            now.year, now.month, now.day, 0, 0, 0, 0, None
        )
        self._parser = parsedatetime.Calendar(version=parsedatetime.VERSION_CONTEXT_STYLE)
github pimutils / todoman / todoman / formatters.py View on Github external
def __init__(self, date_format='%Y-%m-%d', time_format='%H:%M',
                 dt_separator=' ', tz_override=None):
        self.date_format = date_format
        self.time_format = time_format
        self.dt_separator = dt_separator
        self.datetime_format = dt_separator.join(filter(bool, (
            date_format, time_format
        )))

        self.tz = tz_override or tzlocal()
        self.now = datetime.datetime.now().replace(tzinfo=self.tz)

        self._parsedatetime_calendar = parsedatetime.Calendar(
            version=parsedatetime.VERSION_CONTEXT_STYLE,
        )