0

Right, so I've just uploaded about 26,000 notes via this HubSpot endpoint, and i've noticed that a bunch of the uploaded notes have very wrong timestamps (for example instead of being back-dated, or up-to-date, they're flung far into the future).

I've traced the issue back to a portion of my code which uses the Delorean module to make it easier to parse and convert times to epoch timestamps. The issue seems to be that, when I use variable interpolation via the .format() function - it seems to somehow change something.

Example 1 - No interpolation.

def ref_date_epoch():
        parseDate = parse("29/04/2014 00:00:00 -0700")
        getEpoch = parseDate.epoch
        shiftEpoch = epoch(getEpoch).shift("US/Eastern")
        convertEpoch = shiftEpoch.epoch
        testing = int(convertEpoch)
        return "{testing}000".format(testing=testing)

print(ref_date_epoch())
sys.exit()

The above example returns 1398754800000 as the epoch timestamp, which will convert into the correct date - 29/04/2014.

Example 2 - With interpolation.

def ref_date_epoch(datestr):
    if len(datestr) > 0:
        parseDate = parse("{csvDate} 00:00:00 -0700".format(csvDate=datestr))
        getEpoch = parseDate.epoch
        shiftEpoch = epoch(getEpoch).shift("US/Eastern")
        convertEpoch = shiftEpoch.epoch
        testing = int(convertEpoch)
        return "{testing}000".format(testing=testing)
    else:
        None

print(ref_date_epoch(row[2]))
sys.exit()

This time, the above example returns 1597302000000 as the epoch timestamp, which is really, really wrong - it ends up being 13/08/2020. To elaborate, the datestr argument is accepting the list row[2] which references the index of a row in a csv which contains the date.

Example 3. Without the .format() function:

def ref_date_epoch(datestr):
    if len(datestr) > 0:
        parseDate = parse(datestr)
        getEpoch = parseDate.epoch
        shiftEpoch = epoch(getEpoch).shift("US/Eastern")
        convertEpoch = shiftEpoch.epoch
        testing = int(convertEpoch)
        return "{testing}000".format(testing=testing)
    else:
        None

print(ref_date_epoch(row[2]))
sys.exit()

This still returns 1597276800000. It seems that the mere act of indirectly referencing the date seems to change the time. What gives?

Having said all of that - if there is no way to make Delorean work in this way, does any one know of a way to convert a date string to a timestamp with milliseconds?

Edit: I also forgot to mention that many notes were also correct - would the computer that I run the script on impact the creation of the epoch timestamp?

Marko
  • 102
  • 1
  • 10

1 Answers1

0

Nevermind, looks like it was a mixture of a poorly formatted CSV (using dd/mm/yy instead of dd/mm/yyyy and convoluted code. I'm now using this, and it seems to be working:

def ref_date_epoch():
        parseDate = parse(row[2])
        getEpoch = parseDate.epoch
        shiftEpoch = epoch(getEpoch).shift("US/Eastern")
        convertEpoch = shiftEpoch.epoch
        testing = int(convertEpoch)
        return "{testing}000".format(testing=testing)
Marko
  • 102
  • 1
  • 10