Skip to content

Commit

Permalink
deal with missing utc_time
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Darvas committed Mar 30, 2022
1 parent 2705aa8 commit 642ec99
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions micasense/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,21 @@ def position(self):
def utc_time(self):
''' Get the timezone-aware datetime of the image capture '''
str_time = self.get_item('EXIF:DateTimeOriginal')
utc_time = datetime.strptime(str_time, "%Y:%m:%d %H:%M:%S")
subsec = int(self.get_item('EXIF:SubSecTime'))
negative = 1.0
if subsec < 0:
negative = -1.0
subsec *= -1.0
subsec = float('0.{}'.format(int(subsec)))
subsec *= negative
ms = subsec * 1e3
utc_time += timedelta(milliseconds = ms)
timezone = pytz.timezone('UTC')
utc_time = timezone.localize(utc_time)
if str_time is not None:
utc_time = datetime.strptime(str_time, "%Y:%m:%d %H:%M:%S")
subsec = int(self.get_item('EXIF:SubSecTime'))
negative = 1.0
if subsec < 0:
negative = -1.0
subsec *= -1.0
subsec = float('0.{}'.format(int(subsec)))
subsec *= negative
ms = subsec * 1e3
utc_time += timedelta(milliseconds = ms)
timezone = pytz.timezone('UTC')
utc_time = timezone.localize(utc_time)
else:
utc_time = None
return utc_time

def dls_pose(self):
Expand Down

0 comments on commit 642ec99

Please sign in to comment.