# Path: github2/core.py
# @_handle_naive_datetimes
# def datetime_to_ghdate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param datetime datetime_: datetime object to convert
# 
#     """
#     return datetime_.strftime(GITHUB_DATE_FORMAT)
# 
# @_handle_naive_datetimes
# def datetime_to_commitdate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param datetime datetime_: datetime object to convert
# 
#     """
#     date_without_tz = datetime_.strftime(COMMIT_DATE_FORMAT)
#     utcoffset = GITHUB_TZ.utcoffset(datetime_)
#     hours, minutes = divmod(utcoffset.days * 86400 + utcoffset.seconds, 3600)
# 
#     return "".join([date_without_tz, "%+03d:%02d" % (hours, minutes)])
# 
# def datetime_to_isodate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param str datetime_: datetime object to convert
# 
#     .. note:: Supports naive and timezone-aware datetimes
#     """
#     if not datetime_.tzinfo:
#         datetime_ = datetime_.replace(tzinfo=tz.tzutc())
#     else:
#         datetime_ = datetime_.astimezone(tz.tzutc())
#     return "%sZ" % datetime_.isoformat()[:-6]
# 
# def string_to_datetime(string):
#     """Convert a string to Python datetime.
# 
#     :param str github_date: date string to parse
# 
#     """
#     parsed = parser.parse(string)
#     if NAIVE:
#         parsed = parsed.replace(tzinfo=None)
#     return parsed


from datetime import datetime as dt
from nose.tools import eq_
from github2.core import (datetime_to_ghdate, datetime_to_commitdate,
                          datetime_to_isodate, string_to_datetime)
# Commented test cases are in PST, and aren't correctly handled with the
# naïve datetime objects used in the current code base

def test_ghdate_to_datetime():
    eq_(string_to_datetime('2011/05/22 00:24:15 -0700'),
        dt(2011, 5, 22, 0, 24, 15))

    eq_(string_to_datetime('2009/04/18 13:04:09 -0700'),
        dt(2009, 4, 18, 13, 4, 9))
    #eq_(string_to_datetime('2009/11/12 21:15:17 -0800'),
    #    dt(2009, 11, 12, 21, 15, 17))
    #eq_(string_to_datetime('2009/11/12 21:16:20 -0800'),
    #    dt(2009, 11, 12, 21, 16, 20))
    eq_(string_to_datetime('2010/04/17 17:24:29 -0700'),
        dt(2010, 4, 17, 17, 24, 29))
    eq_(string_to_datetime('2010/05/18 06:10:36 -0700'),
        dt(2010, 5, 18, 6, 10, 36))
    eq_(string_to_datetime('2010/05/25 21:59:37 -0700'),
        dt(2010, 5, 25, 21, 59, 37))
    eq_(string_to_datetime('2010/05/26 17:08:41 -0700'),
        dt(2010, 5, 26, 17, 8, 41))
    eq_(string_to_datetime('2010/06/20 06:13:37 -0700'),
        dt(2010, 6, 20, 6, 13, 37))
    eq_(string_to_datetime('2010/07/28 12:56:51 -0700'),
        dt(2010, 7, 28, 12, 56, 51))
    eq_(string_to_datetime('2010/09/20 21:32:49 -0700'),
        dt(2010, 9, 20, 21, 32, 49))


def test_datetime_to_ghdate():

# Path: github2/core.py
# @_handle_naive_datetimes
# def datetime_to_ghdate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param datetime datetime_: datetime object to convert
# 
#     """
#     return datetime_.strftime(GITHUB_DATE_FORMAT)
# 
# @_handle_naive_datetimes
# def datetime_to_commitdate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param datetime datetime_: datetime object to convert
# 
#     """
#     date_without_tz = datetime_.strftime(COMMIT_DATE_FORMAT)
#     utcoffset = GITHUB_TZ.utcoffset(datetime_)
#     hours, minutes = divmod(utcoffset.days * 86400 + utcoffset.seconds, 3600)
# 
#     return "".join([date_without_tz, "%+03d:%02d" % (hours, minutes)])
# 
# def datetime_to_isodate(datetime_):
#     """Convert Python datetime to GitHub date string.
# 
#     :param str datetime_: datetime object to convert
# 
#     .. note:: Supports naive and timezone-aware datetimes
#     """
#     if not datetime_.tzinfo:
#         datetime_ = datetime_.replace(tzinfo=tz.tzutc())
#     else:
#         datetime_ = datetime_.astimezone(tz.tzutc())
#     return "%sZ" % datetime_.isoformat()[:-6]
# 
# def string_to_datetime(string):
#     """Convert a string to Python datetime.
# 
#     :param str github_date: date string to parse
# 
#     """
#     parsed = parser.parse(string)
#     if NAIVE:
#         parsed = parsed.replace(tzinfo=None)
#     return parsed


# Path: tests/test_date_handling.py
from datetime import datetime as dt
from nose.tools import eq_
from github2.core import (datetime_to_ghdate, datetime_to_commitdate,
                          datetime_to_isodate, string_to_datetime)

# Commented test cases are in PST, and aren't correctly handled with the
# naïve datetime objects used in the current code base

def test_ghdate_to_datetime():
    eq_(string_to_datetime('2011/05/22 00:24:15 -0700'),
        dt(2011, 5, 22, 0, 24, 15))

    eq_(string_to_datetime('2009/04/18 13:04:09 -0700'),
        dt(2009, 4, 18, 13, 4, 9))
    #eq_(string_to_datetime('2009/11/12 21:15:17 -0800'),
    #    dt(2009, 11, 12, 21, 15, 17))
    #eq_(string_to_datetime('2009/11/12 21:16:20 -0800'),
    #    dt(2009, 11, 12, 21, 16, 20))
    eq_(string_to_datetime('2010/04/17 17:24:29 -0700'),
        dt(2010, 4, 17, 17, 24, 29))
    eq_(string_to_datetime('2010/05/18 06:10:36 -0700'),
        dt(2010, 5, 18, 6, 10, 36))
    eq_(string_to_datetime('2010/05/25 21:59:37 -0700'),
        dt(2010, 5, 25, 21, 59, 37))
    eq_(string_to_datetime('2010/05/26 17:08:41 -0700'),
        dt(2010, 5, 26, 17, 8, 41))
    eq_(string_to_datetime('2010/06/20 06:13:37 -0700'),
        dt(2010, 6, 20, 6, 13, 37))
    eq_(string_to_datetime('2010/07/28 12:56:51 -0700'),
        dt(2010, 7, 28, 12, 56, 51))
    eq_(string_to_datetime('2010/09/20 21:32:49 -0700'),
        dt(2010, 9, 20, 21, 32, 49))


def test_datetime_to_ghdate():

    eq_(datetime_to_ghdate(dt(2011, 5, 22, 0, 24, 15)),