def ks_get_date_range_from_month(date_state): ks_date_data = {} date = datetime.now() year = date.year month = date.month if date_state=="previous": month -= 1 if month==0: month = 12 year -= 1 end_year = year end_month = month if month == 12: end_year +=1 end_month = 1 else: end_month +=1 ks_date_data["selected_start_date"] = datetime(year, month, 1) ks_date_data["selected_end_date"] = datetime(end_year, end_month, 1)-timedelta(seconds=1) return ks_date_data
def eagle_get_date_range_from_quarter(date_state): eagle_date_data = {} date = datetime.now() year = date.year quarter = int((date.month - 1) / 3) + 1 if date_state == "previous": quarter -= 1 if quarter == 0: quarter = 4 year -= 1 elif date_state == "next": quarter += 1 if quarter == 5: quarter = 1 year += 1 eagle_date_data["selected_start_date"] = datetime(year, 3 * quarter - 2, 1) month = 3 * quarter remaining = int(month / 12) eagle_date_data["selected_end_date"] = datetime( year + remaining, month % 12 + 1, 1) - timedelta(seconds=1) return eagle_date_data
def ks_get_date_range_from_day(date_state): ks_date_data = {} date = datetime.now() if date_state=="previous": date = date-timedelta(days=1) ks_date_data["selected_start_date"] = datetime(date.year,date.month,date.day) ks_date_data["selected_end_date"] = datetime(date.year, date.month, date.day) + timedelta(days=1, seconds=-1) return ks_date_data
def ks_get_date_range_from_year(date_state): ks_date_data = {} date = datetime.now() year = date.year if date_state=="previous": year -= 1 ks_date_data["selected_start_date"] = datetime(year, 1, 1) ks_date_data["selected_end_date"] = datetime(year+1, 1, 1)-timedelta(seconds=1) return ks_date_data
def eagle_get_date_range_from_year(date_state): eagle_date_data = {} date = datetime.now() year = date.year if date_state == "previous": year -= 1 elif date_state == "next": year += 1 eagle_date_data["selected_start_date"] = datetime(year, 1, 1) eagle_date_data["selected_end_date"] = datetime(year + 1, 1, 1) - timedelta(seconds=1) return eagle_date_data