Document stores my ignition tag.timestamp as unicode and I cannot parse it now!

I have a document tag that I am using to store some information and some timestamps. After I perform a system.tag.read(document_tag).value.toDict() on my tag, I get a nice python dictionary, but my timestamps are now unicode! I want to use some of ignitions handy system.date.isBefore() functions on my timestamps stored in the document, but, they must be converted to a dt object first. No probelm right? Wrong!

#Here is the unicode that is coming out of by document value:
time = 'Tue Feb 02 11:49:09 GMT-07:00 2021'

#Here is the best I way I can tell how to parse this string into a dt obj	
time =  system.date.parse(time, "E MMM d H:m:s zXXX yyyy")

I looked thorugh and through the documentation for parsing strings, and this looks correct. I’m sure a simple oversight! It would be nice to have an example of this in the parse examples since I’m sure people have tried to parse these dt objects that have been converted to unicode beofre!

Thanks a bunch ya’ll!

Are you sure it’s actually a string? Try logging/printing type(yourValue).

I believe the issue here is that you are using two place holders for the time zone and in reality you only need 1.

z is the General Time Zone place holder
XXX is the ISO 8601 Time Zone.

Z as defined by the java SimpleDateFormat includes the following format

Remove the XXX and you should get the expected result

time = 'Tue Feb 02 11:49:09 GMT-07:00 2021'

time = system.date.parse(time,'E MMM dd HH:mm:ss z yyyy')

print type(time)
print time

Result

<type 'java.util.Date'>
Tue Feb 02 13:49:09 EST 2021

Note, I’m in the eastern time zone so it converted the time to my time zone.

2 Likes