How to use the tasklib.serializing.local_zone.localize function in tasklib

To help you get started, we’ve selected a few tasklib 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 robgolding / tasklib / tasklib / tests.py View on Github external
def test_simple_eoy_conversion(self):
        if self.tw.version < '2.4.0':
            # Python2.6 does not support SkipTest. As a workaround
            # mark the test as passed by exiting.
            if getattr(unittest, 'SkipTest', None) is not None:
                raise unittest.SkipTest()
            else:
                return

        t = Task(self.tw, description='test task', due='eoy')
        now = local_zone.localize(datetime.datetime.now())
        eoy = local_zone.localize(datetime.datetime(
            year=now.year,
            month=12,
            day=31,
            hour=23,
            minute=59,
            second=59,
            ))
        self.assertEqual(eoy, t['due'])
github robgolding / tasklib / tasklib / tests.py View on Github external
def test_simple_now_conversion(self):
        if self.tw.version < '2.4.0':
            # Python2.6 does not support SkipTest. As a workaround
            # mark the test as passed by exiting.
            if getattr(unittest, 'SkipTest', None) is not None:
                raise unittest.SkipTest()
            else:
                return

        t = Task(self.tw, description='test task', due='now')
        now = local_zone.localize(datetime.datetime.now())

        # Assert that both times are not more than 5 seconds apart
        if sys.version_info < (2, 7):
            self.assertTrue(total_seconds_2_6(now - t['due']) < 5)
            self.assertTrue(total_seconds_2_6(t['due'] - now) < 5)
        else:
            self.assertTrue((now - t['due']).total_seconds() < 5)
            self.assertTrue((t['due'] - now).total_seconds() < 5)
github robgolding / tasklib / tasklib / tests.py View on Github external
def test_complex_eoy_conversion(self):
        if self.tw.version < '2.4.0':
            # Python2.6 does not support SkipTest. As a workaround
            # mark the test as passed by exiting.
            if getattr(unittest, 'SkipTest', None) is not None:
                raise unittest.SkipTest()
            else:
                return

        t = Task(self.tw, description='test task', due='eoy - 4 months')
        now = local_zone.localize(datetime.datetime.now())
        due_date = local_zone.localize(
            datetime.datetime(
                year=now.year,
                month=12,
                day=31,
                hour=23,
                minute=59,
                second=59,
            )
        ) - datetime.timedelta(0, 4 * 30 * 86400)
        self.assertEqual(due_date, t['due'])
github robgolding / tasklib / tasklib / tests.py View on Github external
def test_simple_eoy_conversion(self):
        if self.tw.version < '2.4.0':
            # Python2.6 does not support SkipTest. As a workaround
            # mark the test as passed by exiting.
            if getattr(unittest, 'SkipTest', None) is not None:
                raise unittest.SkipTest()
            else:
                return

        t = Task(self.tw, description='test task', due='eoy')
        now = local_zone.localize(datetime.datetime.now())
        eoy = local_zone.localize(datetime.datetime(
            year=now.year,
            month=12,
            day=31,
            hour=23,
            minute=59,
            second=59,
            ))
        self.assertEqual(eoy, t['due'])
github robgolding / tasklib / tasklib / tests.py View on Github external
def test_complex_eoy_conversion(self):
        if self.tw.version < '2.4.0':
            # Python2.6 does not support SkipTest. As a workaround
            # mark the test as passed by exiting.
            if getattr(unittest, 'SkipTest', None) is not None:
                raise unittest.SkipTest()
            else:
                return

        t = Task(self.tw, description='test task', due='eoy - 4 months')
        now = local_zone.localize(datetime.datetime.now())
        due_date = local_zone.localize(
            datetime.datetime(
                year=now.year,
                month=12,
                day=31,
                hour=23,
                minute=59,
                second=59,
            )
        ) - datetime.timedelta(0, 4 * 30 * 86400)
        self.assertEqual(due_date, t['due'])
github robgolding / tasklib / tasklib / backends.py View on Github external
def convert_datetime_string(self, value):

        if self.version >= self.VERSION_2_4_0:
            # For strings, use 'calc' to evaluate the string to datetime
            # available since TW 2.4.0
            args = value.split()
            result = self.execute_command(['calc'] + args)
            naive = datetime.datetime.strptime(result[0], DATE_FORMAT_CALC)
            localized = local_zone.localize(naive)
        else:
            raise ValueError(
                'Provided value could not be converted to '
                'datetime, its type is not supported: {}'
                .format(type(value)),
            )

        return localized