
from datetime import datetime, timedelta
import pytz


def get_start_times(date):
    """
    date: an epoch integer representing the date that the investment was purchased
    returns the integers (year, month, day)
    """
    datetime_object = datetime.utcfromtimestamp(date)
    return datetime_object.year, datetime_object.month, datetime_object.day


def get_end_times():
    """
    returns the end dates to query pytrends for as integers (year, month, day)
    """
    datetime = get_current_date() - timedelta(days = 1) #get yesterday's date
    return datetime.year, datetime.month, datetime.day


def get_current_date():
    """
    returns the current date in UTC as a datetime object
    """
    utc = pytz.utc
    date = datetime.now(tz=utc)
    return date


def date_to_epoch(date):
    """
    converts date object back into epoch
    """
    return int(date.timestamp())


from datetime import datetime, timezone, timedelta
import pytz


def get_start_times(date):
    """
    date: an epoch integer representing the date that the investment was purchased
    returns the integers (year, month, day)
    """
    datetime_object = datetime.utcfromtimestamp(date)
    return datetime_object.year, datetime_object.month, datetime_object.day


def get_end_times():
    """
    returns the end dates to query pytrends for as integers (year, month, day)
    """
    datetime = get_current_date() - timedelta(days = 1) #get yesterday's date
    return datetime.year, datetime.month, datetime.day


def get_current_date():
    """
    returns the current date in UTC as a datetime object
    """
    utc = pytz.utc
    date = datetime.now(tz=utc)
    return date


def date_to_epoch(date):
    """
    converts date object back into epoch (at exactly midnight utc on day of timestamp)
    """
    year, month, day = date.year, date.month, date.day
    dt = datetime(year=year, month=month, day=day)
    utc_time = dt.replace(tzinfo = timezone.utc) 
    utc_dt = utc_time.timestamp()
    return int(utc_dt)


Fix date to epoch converter to timestamp at exactly midnight
Fix date to epoch converter to timestamp at exactly midnight

  
- from datetime import datetime, timedelta
+ from datetime import datetime, timezone, timedelta
  import pytz
  
  
  def get_start_times(date):
      """
      date: an epoch integer representing the date that the investment was purchased
      returns the integers (year, month, day)
      """
      datetime_object = datetime.utcfromtimestamp(date)
      return datetime_object.year, datetime_object.month, datetime_object.day
  
  
  def get_end_times():
      """
      returns the end dates to query pytrends for as integers (year, month, day)
      """
      datetime = get_current_date() - timedelta(days = 1) #get yesterday's date
      return datetime.year, datetime.month, datetime.day
  
  
  def get_current_date():
      """
      returns the current date in UTC as a datetime object
      """
      utc = pytz.utc
      date = datetime.now(tz=utc)
      return date
  
  
  def date_to_epoch(date):
      """
-     converts date object back into epoch
+     converts date object back into epoch (at exactly midnight utc on day of timestamp)
      """
-     return int(date.timestamp())
+     year, month, day = date.year, date.month, date.day
+     dt = datetime(year=year, month=month, day=day)
+     utc_time = dt.replace(tzinfo = timezone.utc) 
+     utc_dt = utc_time.timestamp()
+     return int(utc_dt)
  
+ 
Fix date to epoch converter to timestamp at exactly midnight
## Code Before:

from datetime import datetime, timedelta
import pytz


def get_start_times(date):
    """
    date: an epoch integer representing the date that the investment was purchased
    returns the integers (year, month, day)
    """
    datetime_object = datetime.utcfromtimestamp(date)
    return datetime_object.year, datetime_object.month, datetime_object.day


def get_end_times():
    """
    returns the end dates to query pytrends for as integers (year, month, day)
    """
    datetime = get_current_date() - timedelta(days = 1) #get yesterday's date
    return datetime.year, datetime.month, datetime.day


def get_current_date():
    """
    returns the current date in UTC as a datetime object
    """
    utc = pytz.utc
    date = datetime.now(tz=utc)
    return date


def date_to_epoch(date):
    """
    converts date object back into epoch
    """
    return int(date.timestamp())

## Instruction:
Fix date to epoch converter to timestamp at exactly midnight
## Code After:

from datetime import datetime, timezone, timedelta
import pytz


def get_start_times(date):
    """
    date: an epoch integer representing the date that the investment was purchased
    returns the integers (year, month, day)
    """
    datetime_object = datetime.utcfromtimestamp(date)
    return datetime_object.year, datetime_object.month, datetime_object.day


def get_end_times():
    """
    returns the end dates to query pytrends for as integers (year, month, day)
    """
    datetime = get_current_date() - timedelta(days = 1) #get yesterday's date
    return datetime.year, datetime.month, datetime.day


def get_current_date():
    """
    returns the current date in UTC as a datetime object
    """
    utc = pytz.utc
    date = datetime.now(tz=utc)
    return date


def date_to_epoch(date):
    """
    converts date object back into epoch (at exactly midnight utc on day of timestamp)
    """
    year, month, day = date.year, date.month, date.day
    dt = datetime(year=year, month=month, day=day)
    utc_time = dt.replace(tzinfo = timezone.utc) 
    utc_dt = utc_time.timestamp()
    return int(utc_dt)

