# Path: yledl/timestamp.py
# def parse_areena_timestamp(timestamp):
#     if timestamp is None:
#         return None
# 
#     timestamp = timestamp.strip()
#     parsed = parse_areena_timestamp_py3(timestamp)
#     if parsed is None:
#         logger.warning(f'Failed to parse timestamp: {timestamp}')
# 
#     return parsed


from datetime import datetime, timedelta
from yledl.timestamp import parse_areena_timestamp


def test_timestamp():
    ts = parse_areena_timestamp('2018-01-02T18:30:00+02:00')

    assert ts.replace(tzinfo=None) == datetime(2018, 1, 2, 18, 30, 00)
    assert ts.utcoffset() == timedelta(hours=2)

    
def test_timestamp_strip():
    ts = parse_areena_timestamp('  2018-01-02T18:30:00+02:00  ')
    assert ts.replace(tzinfo=None) == datetime(2018, 1, 2, 18, 30, 00)

def test_invalid_timestamp():
    assert parse_areena_timestamp('xxx2018-01-02T18:30:00+02:00') is None
    assert parse_areena_timestamp('2018-01-02T18:30:00') is None
    assert parse_areena_timestamp('2018-01-999999T18:30:00+02:00') is None

# Path: yledl/timestamp.py
# def parse_areena_timestamp(timestamp):
#     if timestamp is None:
#         return None
# 
#     timestamp = timestamp.strip()
#     parsed = parse_areena_timestamp_py3(timestamp)
#     if parsed is None:
#         logger.warning(f'Failed to parse timestamp: {timestamp}')
# 
#     return parsed


# Path: tests/test_timestamp.py
from datetime import datetime, timedelta
from yledl.timestamp import parse_areena_timestamp



def test_timestamp():
    ts = parse_areena_timestamp('2018-01-02T18:30:00+02:00')

    assert ts.replace(tzinfo=None) == datetime(2018, 1, 2, 18, 30, 00)
    assert ts.utcoffset() == timedelta(hours=2)

    
def test_timestamp_strip():
    ts = parse_areena_timestamp('  2018-01-02T18:30:00+02:00  ')
    assert ts.replace(tzinfo=None) == datetime(2018, 1, 2, 18, 30, 00)

def test_invalid_timestamp():
    assert parse_areena_timestamp('xxx2018-01-02T18:30:00+02:00') is None
    assert parse_areena_timestamp('2018-01-02T18:30:00') is None
    assert parse_areena_timestamp('2018-01-999999T18:30:00+02:00') is None

    assert parse_areena_timestamp('2018-01-999999T22222') is None