No strptime on the client?

What do you recommend on the client for restoring datetime objects from a JSON value (which can’t handle raw datetimes)?

On the client I ran:

for record in Tvst:
  record['t'] = datetime.strptime(record['t'], '%Y-%m-%d-%H:%M:%S.%f-%z').replace(tzinfo=None)

and got:

NotImplementedError: _strptime is not yet implemented in Skulpt

For dates, I use this:

    """Module 'as_date'.
    Defines function as_date().
    """

    from datetime import date

    def as_date(s): # where s is in ISO format, year in range 1000 thru 9999.
        """Convert an ISO-format date (YYYY-MM-DD) into a date.date"""
        result = date(int(s[0:4]), int(s[5:7]), int(s[8:10]))
        return result

A similar pattern would work for times, and timestamps.

1 Like

Hi @paul.k.pallaghy,

We contribute heavily to Skulpt, an open source library that we use for our Python to Javascript compilation. Strptime is not yet implemnented in Skulpt, but it will come in time!

For now, I’d suggest using an alternate method on the client, as per @p.colbert’s suggestion, or performing your data manipulation on the server.

HI, any news about ```strptime ?

Yes, it’s available now. :slight_smile:

4 Likes