示例#1
0
    def test_ParseDates(self):
        input_date = "2006-01-15"
        d = Date.strptime(input_date, "%Y-%m-%d")
        flag = d == Date(2006, 1, 15)

        self.assertTrue(flag, "date parsing failed\n"
                              " input date:    {0:s}\n"
                              " parsed:        {1}".format(input_date, d))

        input_date = "12/02/2012"
        d = Date.strptime(input_date, "%m/%d/%Y")
        flag = d == Date(2012, 12, 2)

        self.assertTrue(flag, "date parsing failed\n"
                              " input date:    {0:s}\n"
                              " parsed:        {1}".format(input_date, d))

        d = Date.strptime(input_date, "%d/%m/%Y")
        flag = d == Date(2012, 2, 12)

        self.assertTrue(flag, "date parsing failed\n"
                              " input date:    {0:s}\n"
                              " parsed:        {1}".format(input_date, d))

        input_date = "20011002"
        d = Date.strptime(input_date, "%Y%m%d")
        flag = d == Date(2001, 10, 2)

        self.assertTrue(flag, "date parsing failed\n"
                              " input date:    {0:s}\n"
                              " parsed:        {1}".format(input_date, d))
示例#2
0
def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
    """
    :param date: str, datetime, 日期
    :param date_format: str, 时间格式
    :return: PyFin.Date object 
    """
    if isinstance(date, Date):
        return date
    elif isinstance(date, str):
        return Date.strptime(date, date_format)
    else:
        return Date.fromDateTime(date)
示例#3
0
def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
    """
    :param date: str, datetime, 日期
    :param date_format: str, 时间格式
    :return: PyFin.Date object 
    """
    if isinstance(date, Date):
        return date
    elif isinstance(date, str):
        return Date.strptime(date, date_format)
    else:
        return Date.fromDateTime(date)