1# coding: utf-8
2
3from cpython.datetime cimport import_datetime
4from cpython.datetime cimport date, time, datetime, timedelta, timezone_new, PyDateTime_IMPORT
5
6import sys
7
8import_datetime()
9
10def test_date(int year, int month, int day):
11    '''
12    >>> val = test_date(2012, 12, 31)
13    >>> print(val)
14    2012-12-31
15    '''
16    val = date(year, month, day)
17    return val
18
19def test_time(int hour, int minute, int second, int microsecond):
20    '''
21    >>> val = test_time(12, 20, 55, 0)
22    >>> print(val)
23    12:20:55
24    '''
25    val = time(hour, minute, second, microsecond)
26    return val
27
28def test_datetime(int year, int month, int day, int hour, int minute, int second, int microsecond):
29    '''
30    >>> val = test_datetime(2012, 12, 31, 12, 20, 55, 0)
31    >>> print(val)
32    2012-12-31 12:20:55
33    '''
34    val = datetime(year, month, day, hour, minute, second, microsecond)
35    return val
36
37def test_timedelta(int days, int seconds, int useconds):
38    '''
39    >>> val = test_timedelta(30, 0, 0)
40    >>> print(val)
41    30 days, 0:00:00
42    '''
43    val = timedelta(days, seconds, useconds)
44    return val
45
46def test_timezone(int days, int seconds, int useconds, str name):
47    '''
48    >>> val = test_timezone(0, 3600, 0, 'CET')
49    >>> print(val)
50    True
51    '''
52    try:
53        val = timezone_new(timedelta(days, seconds, useconds), name)
54    except RuntimeError:
55        if sys.version_info < (3, 7):
56            return True
57        else:
58            # It's only supposed to raise on Python < 3.7
59            return False
60    else:
61        return True
62