0

What are the fastest ways to convert unix timestamp to local unix timestamp inside a tf.Module. The inputs include timestamp, timezone that are defined as below:

timestamp = tf.constant([1665397419, 1665397419, 1665397419], dtype=tf.int64)
timezone = tf.constant(["America/Los_Angeles", "America/Montreal", "Europe/Helsinki"])

The tf module will have structure like this:

class LocalTime(tf.Module):
    def __init__(self):

    def __call__(self, ts, tz): #timestamp and timezone
        # Do something
        return ts_local # local timestamp

Expected output:

local_time = [1665372219, 1665383019, 1665408219]
Ha An Tran
  • 337
  • 1
  • 21
  • A fast way might be to keep a dict of the offset for each locale in seconds (ie for Helsinki 3*60*60 = 10800) and add as required. You'd have to manually update for summertime etc.. though – bn_ln Nov 02 '22 at 03:11
  • @bn_ln I also have issue with daylight saving times and looking for a way to automatically handle that. – Ha An Tran Nov 02 '22 at 03:13
  • This answer might help https://stackoverflow.com/questions/17733139/getting-the-correct-timezone-offset-in-python-using-local-timezone – bn_ln Nov 02 '22 at 03:16
  • @bn_ln Thanks, I'm still unsure on how to apply an external libraries (i.e. pytz) to a tensor. I checked tf.py_function but still stuck on the implementation. – Ha An Tran Nov 02 '22 at 03:20

0 Answers0