Commit 19282694 authored by Andi Vajda's avatar Andi Vajda
Browse files

carved TimeZone wrappers into timezone.cpp and added tests

parent fff83e27
......@@ -24,6 +24,7 @@ include script.h
include search.h
include shape.h
include spoof.h
include timezone.h
include transliterator.h
include tries.h
include tzinfo.h
......
/* ====================================================================
* Copyright (c) 2004-2019 Open Source Applications Foundation.
* Copyright (c) 2004-2021 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
......@@ -33,6 +33,7 @@
#include "format.h"
#include "dateformat.h"
#include "numberformat.h"
#include "timezone.h"
#include "calendar.h"
#include "collator.h"
#include "charset.h"
......@@ -249,6 +250,7 @@ static PyObject *PyInit_icu(PyObject *m)
_init_format(m);
_init_dateformat(m);
_init_numberformat(m);
_init_timezone(m);
_init_calendar(m);
_init_collator(m);
_init_charset(m);
......
This diff is collapsed.
/* ====================================================================
* Copyright (c) 2004-2010 Open Source Applications Foundation.
* Copyright (c) 2004-2021 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -24,22 +24,9 @@
#ifndef _calendar_h
#define _calendar_h
class t_timezone : public _wrapper {
public:
TimeZone *object;
};
extern PyTypeObject CalendarType_;
extern PyTypeObject TimeZoneType_;
PyObject *wrap_Calendar(Calendar *, int);
PyObject *wrap_TimeZone(TimeZone *, int);
PyObject *wrap_TimeZone(TimeZone *);
PyObject *wrap_TimeZone(const TimeZone &);
PyObject *t_timezone_createTimeZone(PyTypeObject *type, PyObject *arg);
void _init_calendar(PyObject *m);
#endif /* _calendar_h */
/* ====================================================================
* Copyright (c) 2004-2015 Open Source Applications Foundation.
* Copyright (c) 2004-2021 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -27,6 +27,7 @@
#include "bases.h"
#include "locale.h"
#include "format.h"
#include "timezone.h"
#include "calendar.h"
#include "numberformat.h"
#include "dateformat.h"
......
# ====================================================================
# Copyright (c) 2021-2021 Open Source Applications Foundation.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# ====================================================================
#
import sys, os, six, datetime
from unittest import TestCase, main
from icu import *
class TestTimeZone(TestCase):
def testBasic(self):
tz = TimeZone.createTimeZone("America/Los_Angeles")
self.assertTrue(isinstance(tz, BasicTimeZone))
self.assertEquals(str(tz), "America/Los_Angeles")
def testGetRules(self):
tz = TimeZone.createTimeZone("America/Los_Angeles")
rules = tz.getTimeZoneRules()
self.assertTrue(len(rules) > 0)
self.assertTrue(isinstance(rules[0], InitialTimeZoneRule))
for rule in rules[1:]:
self.assertTrue(
isinstance(rule, (TimeArrayTimeZoneRule, AnnualTimeZoneRule)))
def testVTimeZone(self):
vtz = VTimeZone.createVTimeZoneByID("Pacific/Fiji")
data = vtz.write()
vtz.createVTimeZone(data)
self.assertEquals(vtz.write(), data)
data = vtz.writeSimple(
datetime.datetime(2021, 4, 10, 12, 43, 33, 411400))
self.assertTrue(data.startswith(
"BEGIN:VTIMEZONE\r\nTZID:Pacific/Fiji\r\n"))
if ICU_VERSION >= '4.6':
tz = TimeZone.createTimeZone("America/Los_Angeles")
vtz = VTimeZone.createVTimeZoneFromBasicTimeZone(tz)
data = vtz.write()
vtz.createVTimeZone(data)
self.assertEquals(vtz.write(), data)
def testTransition(self):
tz = TimeZone.createTimeZone("Pacific/Fiji")
pytz = ICUtzinfo.getInstance("Pacific/Fiji")
tzr = tz.getNextTransition(
datetime.datetime(2021, 4, 10, 12, 43, 33, tzinfo=pytz))
tzr_time = tzr.getTime()
self.assertEquals(datetime.datetime.fromtimestamp(tzr_time, pytz),
datetime.datetime(2021, 11, 14, 2, 0, tzinfo=pytz))
pytz = ICUtzinfo.getInstance("America/Los_Angeles")
self.assertEquals(datetime.datetime.fromtimestamp(tzr_time, pytz),
datetime.datetime(2021, 11, 13, 6, 0, tzinfo=pytz))
if __name__ == "__main__":
main()
This diff is collapsed.
/* ====================================================================
* Copyright (c) 2004-2021 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* ====================================================================
*/
#ifndef _timezone_h
#define _timezone_h
class t_timezone : public _wrapper {
public:
TimeZone *object;
};
extern PyTypeObject TimeZoneType_;
PyObject *wrap_TimeZone(TimeZone *, int);
PyObject *wrap_TimeZone(TimeZone *);
PyObject *wrap_TimeZone(const TimeZone &);
PyObject *t_timezone_createTimeZone(PyTypeObject *type, PyObject *arg);
void _init_timezone(PyObject *m);
#endif /* _timezone_h */
/* ====================================================================
* Copyright (c) 2007-2014 Open Source Applications Foundation.
* Copyright (c) 2007-2021 Open Source Applications Foundation.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
......@@ -26,7 +26,7 @@
#include "datetime.h"
#include "bases.h"
#include "calendar.h"
#include "timezone.h"
#include "tzinfo.h"
#include "macros.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment