How to use the parsedatetime.context.pdtContext 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 testSources(self):
        self.assertEqual(self.cal.parse('afternoon 5pm')[1],
                         pdtContext(pdtContext.ACU_HALFDAY |
                                    pdtContext.ACU_HOUR))

        self.assertEqual(self.cal.parse('morning')[1],
                         pdtContext(pdtContext.ACU_HALFDAY))

        self.assertEqual(self.cal.parse('night', version=1)[1], 2)
github bear / parsedatetime / tests / TestContext.py View on Github external
def testContext(self):
        self.assertEqual(self.cal.parse('5 min from now')[1],
                         pdtContext(pdtContext.ACU_MIN | pdtContext.ACU_NOW))
        self.assertEqual(self.cal.parse('5 min from now',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 2)
        self.assertEqual(self.cal.parse('7/11/2015')[1],
                         pdtContext(pdtContext.ACU_YEAR |
                                    pdtContext.ACU_MONTH | pdtContext.ACU_DAY))
        self.assertEqual(self.cal.parse('7/11/2015',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 1)
        self.assertEqual(self.cal.parse('14/32/2015')[1],
                         pdtContext(0))
        self.assertEqual(self.cal.parse('25:23')[1],
                         pdtContext())
github bear / parsedatetime / tests / TestContext.py View on Github external
def testContext(self):
        self.assertEqual(self.cal.parse('5 min from now')[1],
                         pdtContext(pdtContext.ACU_MIN | pdtContext.ACU_NOW))
        self.assertEqual(self.cal.parse('5 min from now',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 2)
        self.assertEqual(self.cal.parse('7/11/2015')[1],
                         pdtContext(pdtContext.ACU_YEAR |
                                    pdtContext.ACU_MONTH | pdtContext.ACU_DAY))
        self.assertEqual(self.cal.parse('7/11/2015',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 1)
        self.assertEqual(self.cal.parse('14/32/2015')[1],
                         pdtContext(0))
        self.assertEqual(self.cal.parse('25:23')[1],
                         pdtContext())
github bear / parsedatetime / tests / TestContext.py View on Github external
def testSources(self):
        self.assertEqual(self.cal.parse('afternoon 5pm')[1],
                         pdtContext(pdtContext.ACU_HALFDAY |
                                    pdtContext.ACU_HOUR))

        self.assertEqual(self.cal.parse('morning')[1],
                         pdtContext(pdtContext.ACU_HALFDAY))

        self.assertEqual(self.cal.parse('night', version=1)[1], 2)
github bear / parsedatetime / tests / TestContext.py View on Github external
def testContext(self):
        self.assertEqual(self.cal.parse('5 min from now')[1],
                         pdtContext(pdtContext.ACU_MIN | pdtContext.ACU_NOW))
        self.assertEqual(self.cal.parse('5 min from now',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 2)
        self.assertEqual(self.cal.parse('7/11/2015')[1],
                         pdtContext(pdtContext.ACU_YEAR |
                                    pdtContext.ACU_MONTH | pdtContext.ACU_DAY))
        self.assertEqual(self.cal.parse('7/11/2015',
                                        version=pdt.VERSION_FLAG_STYLE)[1], 1)
        self.assertEqual(self.cal.parse('14/32/2015')[1],
                         pdtContext(0))
        self.assertEqual(self.cal.parse('25:23')[1],
                         pdtContext())
github bear / parsedatetime / parsedatetime / __init__.py View on Github external
def context(self):
        ctx = pdtContext()
        self._ctxStack.push(ctx)
        yield ctx
        ctx = self._ctxStack.pop()
        if not self._ctxStack.isEmpty():
            self.currentContext.update(ctx)
github bear / parsedatetime / parsedatetime / __init__.py View on Github external
def _evalTimeStr(self, datetimeString, sourceTime):
        """
        Evaluate text passed by L{_partialParseTimeStr()}
        """
        s = datetimeString.strip()
        sourceTime = self._evalDT(datetimeString, sourceTime)

        if s in self.ptc.re_values['now']:
            self.currentContext.updateAccuracy(pdtContext.ACU_NOW)
        else:
            # Given string is a natural language time string like
            # lunch, midnight, etc
            sTime = self.ptc.getSource(s, sourceTime)
            if sTime:
                sourceTime = sTime
            self.currentContext.updateAccuracy(pdtContext.ACU_HALFDAY)

        return sourceTime
github bear / parsedatetime / parsedatetime / __init__.py View on Github external
v3 = int(s[index + 1:])
        else:
            v2 = int(s.strip())

        v = [v1, v2, v3]
        d = {'m': mth, 'd': dy, 'y': yr}

        # yyyy/mm/dd format
        dp_order = self.ptc.dp_order if v1 <= 31 else ['y', 'm', 'd']

        for i in range(0, 3):
            n = v[i]
            c = dp_order[i]
            if n >= 0:
                d[c] = n
                accuracy.append({'m': pdtContext.ACU_MONTH,
                                 'd': pdtContext.ACU_DAY,
                                 'y': pdtContext.ACU_YEAR}[c])

        # if the year is not specified and the date has already
        # passed, increment the year
        if v3 == -1 and ((mth > d['m']) or (mth == d['m'] and dy > d['d'])):
            yr = d['y'] + self.ptc.YearParseStyle
        else:
            yr = d['y']

        mth = d['m']
        dy = d['d']

        # birthday epoch constraint
        if yr < self.ptc.BirthdayEpoch:
            yr += 2000
github bear / parsedatetime / parsedatetime / __init__.py View on Github external
v2 = int(s.strip())

        v = [v1, v2, v3]
        d = {'m': mth, 'd': dy, 'y': yr}

        # yyyy/mm/dd format
        dp_order = self.ptc.dp_order if v1 <= 31 else ['y', 'm', 'd']

        for i in range(0, 3):
            n = v[i]
            c = dp_order[i]
            if n >= 0:
                d[c] = n
                accuracy.append({'m': pdtContext.ACU_MONTH,
                                 'd': pdtContext.ACU_DAY,
                                 'y': pdtContext.ACU_YEAR}[c])

        # if the year is not specified and the date has already
        # passed, increment the year
        if v3 == -1 and ((mth > d['m']) or (mth == d['m'] and dy > d['d'])):
            yr = d['y'] + self.ptc.YearParseStyle
        else:
            yr = d['y']

        mth = d['m']
        dy = d['d']

        # birthday epoch constraint
        if yr < self.ptc.BirthdayEpoch:
            yr += 2000
        elif yr < 100:
            yr += 1900