# Path: fooltrader/contract/data_contract.py
# TICK_COL = ['timestamp', 'price', 'volume', 'turnover', 'direction']
# 
# Path: fooltrader/contract/files_contract.py
# def get_tick_path(item, date):
#     return os.path.join(get_tick_dir(item), date + ".csv")
# 
# Path: fooltrader/settings.py
# TIME_FORMAT_DAY = '%Y-%m-%d'
# 
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"


import datetime
import logging
import os
import pandas as pd
from logging.handlers import RotatingFileHandler
from fooltrader.contract.data_contract import TICK_COL
from fooltrader.contract.files_contract import get_tick_path
from fooltrader.settings import TIME_FORMAT_DAY, TIME_FORMAT_MICRO
def is_same_date(one, two):
    return to_timestamp(one).date() == to_timestamp(two).date()


def is_same_time(one, two):
    return to_timestamp(one) == to_timestamp(two)


def get_report_period(the_date=datetime.datetime.today().date()):
    if the_date.month >= 10:
        return "{}{}".format(the_date.year, '-09-30')
    elif the_date.month >= 7:
        return "{}{}".format(the_date.year, '-06-30')
    elif the_date.month >= 4:
        return "{}{}".format(the_date.year, '-03-31')
    else:
        return "{}{}".format(the_date.year - 1, '-12-31')


# ms(int) or second(float) or str
def to_timestamp(the_time):
    if type(the_time) == int:
        the_time = the_time / 1000.0

    if type(the_time) == float:
        return pd.Timestamp.fromtimestamp(the_time)

    return pd.Timestamp(the_time)



# Path: fooltrader/contract/data_contract.py
# TICK_COL = ['timestamp', 'price', 'volume', 'turnover', 'direction']
# 
# Path: fooltrader/contract/files_contract.py
# def get_tick_path(item, date):
#     return os.path.join(get_tick_dir(item), date + ".csv")
# 
# Path: fooltrader/settings.py
# TIME_FORMAT_DAY = '%Y-%m-%d'
# 
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"


# Path: fooltrader/utils/utils.py
import datetime
import logging
import os
import pandas as pd
from logging.handlers import RotatingFileHandler
from fooltrader.contract.data_contract import TICK_COL
from fooltrader.contract.files_contract import get_tick_path
from fooltrader.settings import TIME_FORMAT_DAY, TIME_FORMAT_MICRO

def is_same_date(one, two):
    return to_timestamp(one).date() == to_timestamp(two).date()


def is_same_time(one, two):
    return to_timestamp(one) == to_timestamp(two)


def get_report_period(the_date=datetime.datetime.today().date()):
    if the_date.month >= 10:
        return "{}{}".format(the_date.year, '-09-30')
    elif the_date.month >= 7:
        return "{}{}".format(the_date.year, '-06-30')
    elif the_date.month >= 4:
        return "{}{}".format(the_date.year, '-03-31')
    else:
        return "{}{}".format(the_date.year - 1, '-12-31')


# ms(int) or second(float) or str
def to_timestamp(the_time):
    if type(the_time) == int:
        the_time = the_time / 1000.0

    if type(the_time) == float:
        return pd.Timestamp.fromtimestamp(the_time)

    return pd.Timestamp(the_time)



def to_time_str(the_time, time_fmt=TIME_FORMAT_DAY):