Python dateutil.tz 模块,tzoffset() 实例源码

我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用dateutil.tz.tzoffset()

项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testTzAll(self):
        from dateutil.tz import tzutc
        from dateutil.tz import tzoffset
        from dateutil.tz import tzlocal
        from dateutil.tz import tzfile
        from dateutil.tz import tzrange
        from dateutil.tz import tzstr
        from dateutil.tz import tzical
        from dateutil.tz import gettz
        from dateutil.tz import tzwin
        from dateutil.tz import tzwinlocal

        tz_all = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
                  "tzstr", "tzical", "gettz"]

        tz_all += ["tzwin", "tzwinlocal"] if sys.platform.startswith("win") else []
        lvars = locals()

        for var in tz_all:
            self.assertIsNot(lvars[var], None)
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_naive_timestamp_default_timezone(self):
        """
        The incoming value is a naive timestamp, but the Filter is
        configured not to treat naive timestamps as UTC.
        """
        self.assertFilterPasses(
            self._filter(
                '2015-05-12 03:20:03',

                # The Filter is configured to parse naive timestamps as
                # if they are UTC+8.
                timezone = tzoffset('UTC+8', 8*3600)
            ),

            # The resulting date appears to occur 1 day earlier because
            # the Filter subtracted 8 hours to convert the value to
            # UTC.
            date(2015, 5, 11),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_aware_timestamp_default_timezone(self):
        """
        The Filter's default timezone has no effect if the incoming
        value already contains timezone info.
        """
        self.assertFilterPasses(
            # The incoming timestamp is from UTC+4, but the Filter is
            # configured to use UTC-11 by default.
            self._filter(
                '2015-05-11T03:14:38+04:00',
                timezone = tzoffset('UTC-11', -11*3600)
            ),

            # Because the incoming timestamp has timezone info, the
            # Filter uses that instead of the default value.
            # Note that the this test will fail if the Filter uses the
            # UTC-11 timezone (the result will be 1 day ahead).
            date(2015, 5, 10),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_naive_timestamp_default_timezone(self):
        """
        The incoming value is a naive timestamp, but the Filter is
        configured not to treat naive timestamps as UTC.
        """
        self.assertFilterPasses(
            # The incoming value is a naive timestamp, and the Filter
            # is configured to use UTC+8 by default.
            self._filter(
                '2015-05-12 09:20:03',
                timezone = tzoffset('UTC+8', 8*3600),
            ),

            # The resulting datetime is still converted to UTC.
            datetime(2015, 5, 12, 1, 20, 3, tzinfo=utc),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_return_naive_datetime(self):
        """
        You can configure the filter to return a naive datetime object
        (e.g., for storing in a database).

        Note that the datetime is still converted to UTC before its
        tzinfo is removed.
        """
        self.assertFilterPasses(
            self._filter(
                datetime(
                    2015, 7, 1, 9, 22, 10,
                    tzinfo=tzoffset('UTC-5', -5*3600),
                ),

                # Note that we pass `naive=True` to the Filter's
                # initializer.
                naive = True,
            ),

            # The resulting datetime is converted to UTC before its
            # timezone info is stripped.
            datetime(2015, 7, 1, 14, 22, 10, tzinfo=None),
        )
项目:ws-backend-community    作者:lavalamp-    | 项目源码 | 文件源码
def now():
        """
        Get the current datetime.
        :return: The current datetime.
        """
        return datetime.utcnow().replace(tzinfo=tzoffset(None, 0))

    # Class Methods

    # Public Methods

    # Protected Methods

    # Private Methods

    # Properties

    # Representation and Comparison
项目:riko    作者:nerevu    | 项目源码 | 文件源码
def normalize_date(date):
    try:
        # See if date is a `time.struct_time`
        # if so, convert it and account for leapseconds
        tt, date = date, dt(*date[:5] + (min(date[5], 59),))
    except TypeError:
        pass
    else:
        is_dst = None if tt[8] is -1 else tt[8]

        try:
            tm_zone = tt.tm_zone
        except AttributeError:
            tm_zone = None
            tm_gmtoff = None
        else:
            tm_gmtoff = tt.tm_gmtoff

        if tm_zone:
            date = pytz.timezone(tm_zone).localize(date, is_dst=is_dst)
        elif tm_gmtoff:
            offset = tzoffset(None, tm_gmtoff)
            date.replace(tzinfo=offset)

    # Set timezone to UTC
    try:
        tzdate = date.astimezone(utc) if date.tzinfo else utc.localize(date)
    except AttributeError:
        tzdate = date

    return tzdate
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def setUp(self):
        self.tzinfos = {"BRST": -10800}
        self.brsttz = tzoffset("BRST", -10800)
        self.default = datetime(2003, 9, 25)

        # Parser should be able to handle bytestring and unicode
        base_str = '2014-05-01 08:00:00'
        try:
            # Python 2.x
            self.uni_str = unicode(base_str)
            self.str_str = str(base_str)
        except NameError:
            self.uni_str = str(base_str)
            self.str_str = bytes(base_str.encode())
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testInequality(self):
        UTC = tz.tzutc()
        UTCp4 = tz.tzoffset('UTC+4', 14400)

        self.assertNotEqual(UTC, UTCp4)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testTimedeltaOffset(self):
        est = tz.tzoffset('EST', timedelta(hours=-5))
        est_s = tz.tzoffset('EST', -18000)

        self.assertEqual(est, est_s)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testTzNameNone(self):
        gmt5 = tz.tzoffset(None, -18000)       # -5:00
        self.assertIs(datetime(2003, 10, 26, 0, 0, tzinfo=gmt5).tzname(),
                      None)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testTzOffsetRepr(self):
        tname = 'EST'
        tzo = tz.tzoffset(tname, -5 * 3600)
        self.assertEqual(repr(tzo), "tzoffset(" + repr(tname) + ", -18000)")
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testEquality(self):
        utc = tz.tzoffset('UTC', 0)
        gmt = tz.tzoffset('GMT', 0)

        self.assertEqual(utc, gmt)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testUTCEquality(self):
        utc = tz.tzutc()
        o_utc = tz.tzoffset('UTC', 0)

        self.assertEqual(utc, o_utc)
        self.assertEqual(o_utc, utc)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testInequalityInvalid(self):
        tzo = tz.tzoffset('-3', -3 * 3600)
        self.assertFalse(tzo == -3)
        self.assertNotEqual(tzo, -3)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testInequalityUnsupported(self):
        tzo = tz.tzoffset('-5', -5 * 3600)

        self.assertTrue(tzo == ComparesEqual)
        self.assertFalse(tzo != ComparesEqual)
        self.assertEqual(tzo, ComparesEqual)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testInequalityFixedOffset(self):
        tzl = tz.tzlocal()
        tzos = tz.tzoffset('LST', total_seconds(tzl._std_offset))
        tzod = tz.tzoffset('LDT', total_seconds(tzl._std_offset))

        self.assertFalse(tzl == tzos)
        self.assertFalse(tzl == tzod)
        self.assertTrue(tzl != tzos)
        self.assertTrue(tzl != tzod)
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testPickleTzOffsetZero(self):
        self.assertPicklable(tz.tzoffset('UTC', 0))
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testPickleTzOffsetPos(self):
        self.assertPicklable(tz.tzoffset('UTC+1', 3600))
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
def testPickleTzOffsetNeg(self):
        self.assertPicklable(tz.tzoffset('UTC-1', -3600))
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_alternate_timezone_syntax(self):
        """
        When setting the default timezone for the Filter, you can use
        an int/float offset (number of hours from UTC) instead of a
        tzoffset object.
        """
        self.assertFilterPasses(
            # Note that we use an int value instead of constructing a
            # tzoffset for `timezone`.
            self._filter('2015-05-11 21:14:38', timezone=-8),
            date(2015, 5, 12),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_datetime_non_utc(self):
        """
        The incoming value is a datetime object with a non-UTC
        timezone.
        """
        self.assertFilterPasses(
            datetime(
                2015, 6, 27, 22, 6, 32,
                tzinfo=tzoffset('UTC-5', -5*3600),
            ),

            # As you probably already guessed, the datetime gets
            # converted to UTC before it is converted to a date.
            date(2015, 6, 28),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_alternate_timezone_syntax(self):
        """
        When setting the default timezone for the Filter, you can use
        an int/float offset (number of hours from UTC) instead of a
        tzoffset object.
        """
        self.assertFilterPasses(
            # Note that we use an int value instead of constructing a
            # tzoffset for ``timezone``.
            self._filter('2015-05-11 21:14:38', timezone=3),

            datetime(2015, 5, 11, 18, 14, 38, tzinfo=utc),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def test_pass_datetime_non_utc(self):
        """
        The incoming value is a datetime object that is already set to
        a non-UTC timezone.
        """
        self.assertFilterPasses(
            datetime(2015, 6, 27, 10, 6, 32, tzinfo=tzoffset('UTC-5',-5*3600)),
            datetime(2015, 6, 27, 15, 6, 32, tzinfo=utc),
        )
项目:filters    作者:eflglobal    | 项目源码 | 文件源码
def __init__(self, timezone=None, naive=False):
        # type: (Optional[Union[tzinfo, int, float]], bool) -> None
        """
        :param timezone:
            Specifies the timezone to use when the *incoming* value is
            a naive timestamp.  Has no effect on timezone-aware
            timestamps.

            IMPORTANT:  The result is always converted to UTC,
            regardless of the value of the ``timezone`` param!

            You can provide an int/float here, which is the offset from
            UTC in hours (e.g., 5 = UTC+5).

        :param naive:
            If True, the filter will *return* naive datetime objects
            (sans tzinfo).  This is useful e.g., for datetimes that
            will be stored in a database that doesn't understand aware
            timestamps.

            IMPORTANT:  Incoming values are still converted to UTC
            before stripping tzinfo!
        """
        super(Datetime, self).__init__()

        if not isinstance(timezone, tzinfo):
            if timezone in [0, None]:
                timezone = utc
            else:
                # Assume that we got an int/float instead.
                timezone = tzoffset(
                    name    = 'UTC{offset:+}'.format(offset=timezone),
                    offset  = float(timezone) * 3600.0,
                )

        self.timezone   = timezone
        self.naive      = naive
项目:Orator-Google-App-Engine    作者:MakarenaLabs    | 项目源码 | 文件源码
def parse(cls, string):

        tzinfo = None

        if string == 'local':
            tzinfo = tz.tzlocal()

        elif string in ['utc', 'UTC']:
            tzinfo = tz.tzutc()

        else:

            iso_match = cls._TZINFO_RE.match(string)

            if iso_match:
                sign, hours, minutes = iso_match.groups()
                seconds = int(hours) * 3600 + int(minutes) * 60

                if sign == '-':
                    seconds *= -1

                tzinfo = tz.tzoffset(None, seconds)

            else:
                tzinfo = tz.gettz(string)

        if tzinfo is None:
            raise ParserError('Could not parse timezone expression "{0}"', string)

        return tzinfo
项目:whenareyou    作者:aerupt    | 项目源码 | 文件源码
def whenareyou_apt(airport):
    if not airports_dict[airport]['tz_olson']=='\\N':
        return timezone(airports_dict[airport]['tz_olson'])
    else:
        tzinfo = get_tz(float(airports_dict[airport]['lat']),
                        float(airports_dict[airport]['lng']))
        if tzinfo:
            return tzinfo
        else:
            tot_offset = float(airports_dict[airport]['tz'])*3600
            return tz.tzoffset(airports_dict[airport]['name'] + ' ' +
                               airports_dict[airport]['city'], tot_offset)
项目:twtxt    作者:buckket    | 项目源码 | 文件源码
def test_parse_iso8601():
    """Test parsing ISO-8601 date/time strings."""
    as_string = "2016-02-05T02:52:15.030474+01:00"
    as_datetime = datetime(2016, 2, 5, 2, 52, 15, 30474, tzinfo=tzoffset(None, 3600))
    assert parse_iso8601(as_string) == as_datetime

    as_string = "2016-02-05T02:52:15"
    as_datetime = datetime(2016, 2, 5, 2, 52, 15, tzinfo=timezone.utc)
    assert parse_iso8601(as_string) == as_datetime

    with pytest.raises(ValueError) as e:
        parse_iso8601("foobar")
    assert "Unknown string format" in str(e.value)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_timestamp_to_datetime_tzoffset(self):
        # tzoffset
        from dateutil.tz import tzoffset
        tzinfo = tzoffset(None, 7200)
        expected = Timestamp('3/11/2012 04:00', tz=tzinfo)
        result = Timestamp(expected.to_datetime())
        self.assertEqual(expected, result)
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_dateutil_tzoffset_support(self):
        from dateutil.tz import tzoffset
        values = [188.5, 328.25]
        tzinfo = tzoffset(None, 7200)
        index = [datetime(2012, 5, 11, 11, tzinfo=tzinfo),
                 datetime(2012, 5, 11, 12, tzinfo=tzinfo)]
        series = Series(data=values, index=index)

        self.assertEqual(series.index.tz, tzinfo)

        # it works! #2443
        repr(series.index[0])
项目:slack_scholar    作者:xLeitix    | 项目源码 | 文件源码
def parse(cls, string):

        tzinfo = None

        if string == 'local':
            tzinfo = tz.tzlocal()

        elif string in ['utc', 'UTC']:
            tzinfo = tz.tzutc()

        else:

            iso_match = cls._TZINFO_RE.match(string)

            if iso_match:
                sign, hours, minutes = iso_match.groups()
                if minutes is None:
                    minutes = 0
                seconds = int(hours) * 3600 + int(minutes) * 60

                if sign == '-':
                    seconds *= -1

                tzinfo = tz.tzoffset(None, seconds)

            else:
                tzinfo = tz.gettz(string)

        if tzinfo is None:
            raise ParserError('Could not parse timezone expression "{0}"', string)

        return tzinfo
项目:javaproperties    作者:jwodder    | 项目源码 | 文件源码
def test_dumps_aware_datetime():
    assert dumps(
        {"key": "value"},
        timestamp=datetime.fromtimestamp(1473703254, tzoffset('PDT', -25200))
    ) == '#Mon Sep 12 11:00:54 PDT 2016\nkey=value\n'
项目:bloomsky-api    作者:tylerdave    | 项目源码 | 文件源码
def _timestamp_to_iso_format(timestamp, offset_hours=0):
        try:
            pseudo_timezone = tz.tzoffset('Unknown', int(offset_hours * 3600))
            return datetime.fromtimestamp(timestamp, pseudo_timezone).isoformat()
        except:
            raise
            return None
项目:bernard    作者:BernardFW    | 项目源码 | 文件源码
def test_make_date():
    d = datetime.date(2000, 1, 1)
    assert make_date(d) == d

    d2 = datetime.datetime(2000, 1, 1, 0, 0)
    assert make_date(d2) == d

    d3 = '2000-01-01T00:00:00.000000Z'
    assert make_date(d3) == d

    test_tz = pytz.timezone('America/Cancun')
    assert make_date(d3, test_tz) != d

    test_tz = tz.tzoffset('IST', -3600)
    assert make_date(d3, test_tz) != d
项目:bernard    作者:BernardFW    | 项目源码 | 文件源码
def test_format_date():
    test_tz = tz.tzoffset('IST', -3600)
    f = I18nFormatter('fr', test_tz)

    d = '2000-01-01T00:00:00.000000Z'

    assert f.format('Posté le {post_date:date:medium}', post_date=d) == \
        'Posté le 1 janv. 2000'
项目:bernard    作者:BernardFW    | 项目源码 | 文件源码
def get_timezone(self) -> Optional[tzinfo]:
        """
        We can't exactly know the time zone of the user from what Facebook
        gives (fucking morons) but we can still give something that'll work
        until next DST.
        """

        u = await self._get_user()
        diff = float(u.get('timezone', 0)) * 3600.0

        return tz.tzoffset('ITC', diff)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def parse(cls, string):

        tzinfo = None

        if string == 'local':
            tzinfo = tz.tzlocal()

        elif string in ['utc', 'UTC']:
            tzinfo = tz.tzutc()

        else:

            iso_match = cls._TZINFO_RE.match(string)

            if iso_match:
                sign, hours, minutes = iso_match.groups()
                if minutes is None:
                    minutes = 0
                seconds = int(hours) * 3600 + int(minutes) * 60

                if sign == '-':
                    seconds *= -1

                tzinfo = tz.tzoffset(None, seconds)

            else:
                tzinfo = tz.gettz(string)

        if tzinfo is None:
            raise ParserError('Could not parse timezone expression "{0}"'.format(string))

        return tzinfo
项目:trafaret    作者:Deepwalker    | 项目源码 | 文件源码
def test_datetime(self):
        check = DateTime()
        self.assertEqual(check('2017-09-01 23:59'),
                         datetime.datetime(2017, 9, 1, 23, 59))
        self.assertEqual(
            check('Fri Sep 1 23:59:59 UTC 2017'),
            datetime.datetime(2017, 9, 1, 23, 59, 59, tzinfo=tzutc()))
        self.assertEqual(
            check('Fri Sep 1 23:59:59 2017'),
            datetime.datetime(2017, 9, 1, 23, 59, 59))
        self.assertEqual(
            check('Fri, 1 Sep 2017 23:59:59 -0300'),
            datetime.datetime(2017, 9, 1, 23, 59, 59,
                              tzinfo=tzoffset(None, -10800)))
        self.assertEqual(
            check('2017-09-01T23:59:59.5-03:00'),
            datetime.datetime(2017, 9, 1, 23, 59, 59, 500000,
                              tzinfo=tzoffset(None, -10800)))
        self.assertEqual(
            check('20170901T235959.5-0300'),
            datetime.datetime(2017, 9, 1, 23, 59, 59, 500000,
                              tzinfo=tzoffset(None, -10800)))
        self.assertEqual(
            check('20170901T235959-0300'),
            datetime.datetime(2017, 9, 1, 23, 59, 59,
                              tzinfo=tzoffset(None, -10800)))
        self.assertEqual(check('2017-09-01T23:59:59'),
                         datetime.datetime(2017, 9, 1, 23, 59, 59))
        self.assertEqual(check('20170901T235959'),
                         datetime.datetime(2017, 9, 1, 23, 59, 59))
        self.assertEqual(check('20170901235959'),
                         datetime.datetime(2017, 9, 1, 23, 59, 59))
        self.assertEqual(check('2017-09-01T23:59'),
                         datetime.datetime(2017, 9, 1, 23, 59))
        self.assertEqual(check('20170901T2359'),
                         datetime.datetime(2017, 9, 1, 23, 59))
        self.assertEqual(check('2017-09-01T23'),
                         datetime.datetime(2017, 9, 1, 23))
        self.assertEqual(check('20170901T23'),
                         datetime.datetime(2017, 9, 1, 23))
        self.assertEqual(check('2017-09-01'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('20170901'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('09-01-2017'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('09-01-17'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('2017.Sep.01'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('2017/09/01'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('2017 09 01'),
                         datetime.datetime(2017, 9, 1))
        self.assertEqual(check('1st of September 2017'),
                         datetime.datetime(2017, 9, 1))

        # Note: to equality here we need to pass extra params to parse() method
        self.assertNotEqual(check('01-09-2017'),
                            datetime.datetime(2017, 9, 1))
项目:mailingListScraper    作者:gaalcaras    | 项目源码 | 文件源码
def process_item(self, item, spider):
        times = {
            'timestampSent': 'timeSent',
            'timestampReceived': 'timeReceived'
        }

        time_format = "%Y-%m-%d %H:%M:%S%z"

        # Define a default time zone according to the email server setting
        if spider.name == 'hypermail':
            def_tz = tz.tzoffset('EST', -18000)
        elif spider.name == 'marc':
            def_tz = tz.tzoffset('EDT', -14400)

        for key, val in times.items():
            if item[val] == "":
                item[val] = "NA"
                item[key] = "NA"
                continue

            try:
                parsed_time = dateParser(item[val])
            except ValueError:
                try:
                    # "... HH:MM:SS +0200"
                    pattern = r'(.* \d{2}:\d{2}:\d{2}(\s?[+,-]\d{4})?)'
                    simpler = re.search(pattern, item[val])
                    parsed_time = dateParser(simpler.group(1))
                except AttributeError:
                    message = '<' + item['url'] + '> '
                    message += 'ParseTimeFields could not parse ' + val + ', '
                    message += key + ' will be NA.'
                    LOGGER.warning(message)
                    item[key] = "NA"
                    continue

            if parsed_time.tzinfo is None:
                parsed_time = parsed_time.replace(tzinfo=def_tz)

            item[key] = parsed_time.strftime(time_format)

        return item
项目:docker-iot-calendar    作者:masterandrey    | 项目源码 | 文件源码
def test():
    from io import BytesIO
    x = [datetime.datetime(2017, 4, 6, 0, 0), datetime.datetime(2017, 4, 7, 0, 0), datetime.datetime(2017, 4, 8, 0, 0), datetime.datetime(2017, 4, 11, 0, 0), datetime.datetime(2017, 4, 12, 0, 0), datetime.datetime(2017, 4, 13, 0, 0), datetime.datetime(2017, 4, 14, 0, 0), datetime.datetime(2017, 4, 16, 0, 0), datetime.datetime(2017, 4, 17, 0, 0),
         datetime.datetime(2017, 4, 18, 0, 0), datetime.datetime(2017, 4, 19, 0, 0), datetime.datetime(2017, 4, 20, 0, 0), datetime.datetime(2017, 4, 22, 0, 0), datetime.datetime(2017, 4, 23, 0, 0)]
    y = [[0.0, 15.0, 9.0, 0.0, 9.0, 5.0, 6.0, 0.0, 11.0, 9.0, 5.0, 6.0, 0.0, 11.0],
         [15.0, 17.0, 0.0, 20.0, 20.0, 19.0, 30.0, 32.0, 23.0, 20.0, 19.0, 30.0, 32.0, 23.0]]
    grid = [
        [{'date': datetime.datetime(2017, 4, 3, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 4, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 5, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 6, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  0.,  15.]}, {'date': datetime.datetime(2017, 4, 7, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 15.,  17.]}, {'date': datetime.datetime(2017, 4, 8, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 9.,  0.]}, {'date': datetime.datetime(2017, 4, 9, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}],
        [{'date': datetime.datetime(2017, 4, 10, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 11, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  0.,  20.]}, {'date': datetime.datetime(2017, 4, 12, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  9.,  20.]}, {'date': datetime.datetime(2017, 4, 13, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  5.,  19.]}, {'date': datetime.datetime(2017, 4, 14, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  6.,  30.]}, {'date': datetime.datetime(2017, 4, 15, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 16, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [  0.,  32.]}],
        [{'date': datetime.datetime(2017, 4, 17, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 11.,  23.]}, {'date': datetime.datetime(2017, 4, 18, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 19, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 20, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 21, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 22, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 23, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}],
        [{'date': datetime.datetime(2017, 4, 24, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 11.,  23.]}, {'date': datetime.datetime(2017, 4, 25, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 26, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 27, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 28, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 29, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}, {'date': datetime.datetime(2017, 4, 30, 0, 0, tzinfo=tzoffset(None, 10800)), 'values': [ 0.,  0.]}]
            ]
    dashboard = {
        "summary": "Anna work-out",
        "empty_image": "../amazon-dash-private/images/old-woman.png",
        "images_folder": "../amazon-dash-private/images/"
    }
    labels = [
        {"summary": "Morning work-out", "image": "../amazon-dash-private/images/morning4.png"},
        {"summary": "Physiotherapy", "image": "../amazon-dash-private/images/evening2.png"}
    ]
    absent_labels = [
        {'image_grid': '../amazon-dash-private/images/absent_ill_grid.png',
         'image_plot': '../amazon-dash-private/images/absent_ill_plot.png',
        'summary': 'Sick'},
        {'image_grid': '../amazon-dash-private/images/absent_vacation_grid.png',
         'image_plot': '../amazon-dash-private/images/absent_vacation_plot.png',
         'summary': 'Vacation'}
    ]
    weather = {'day': [datetime.datetime(2017, 4, 22, 0, 0),
                       datetime.datetime(2017, 4, 23, 0, 0),
                       datetime.datetime(2017, 4, 24, 0, 0),
                       datetime.datetime(2017, 4, 25, 0, 0)],
               'icon': ['sct', 'ovc', 'hi_shwrs', 'sn'],
               'temp_max': [6.64, 6.38, 4.07, 6.91],
               'temp_min': [-0.58, -2.86, -1.87, -1.91],
               'images_folder': '../amazon-dash-private/images/'}
    t0 = datetime.datetime.now()
    image_data = draw_calendar(grid, x, y, weather, dashboard, labels, absent_labels,
                               ImageParams(
                                   dashboard='',
                                   format='gif',
                                   style='seaborn-talk',
                                   xkcd=1,
                                   rotate=0
                               )
                               )
    t1 = datetime.datetime.now()
    print(t1 - t0)
    image_file = BytesIO(image_data)
    image = PIL.Image.open(image_file)
    image.show()
    # with open('test.png', 'wb') as png_file:
    #     png_file.write(image)
    #plt.show()
    #todo speed it up. too many rescalings as I see from profiling.
    # may be using artists (http://stackoverflow.com/questions/41453902/is-it-possible-to-patch-an-image-in-matplotlib)
    # will reduce number of rescaling?
    # now it looks like matplotlib rescales after each operation