USRA-STI / gdt-fermi

Gamma-ray Data Tools - Fermi mission components
Apache License 2.0
2 stars 3 forks source link

Add datetime conversion with timezone info for Time.py #12

Closed rachel-hamburg closed 3 months ago

rachel-hamburg commented 9 months ago

For example, when converting an MET to datetime, I use

from gdt.missions.fermi.time import Time t1 = Time(trigtime, format='fermi', scale='utc').datetime

This object does not have timezone information and when comparing to another datetime object, e.g.,

t2 = datetime.datetime(y, m, d, dt, tzinfo=datetime.timezone.utc),

I receive this error: TypeError: can't compare offset-naive and offset-aware datetimes

However, in the GBM Data Tools, when using from gbm.time import Met t = Met(met)

This automatically returns a datetime object with the UTC timezone specified: self.__time.utc.to_datetime(datetime.timezone.utc)

It would be nice to have this capability in the GDT without having to call from gdt.missions.fermi.time import Time t1 = Time(trigtime, format='fermi', scale='utc') t1 = t1.to_datetime(datetime.timezone.utc)

BillCleveland-USRA commented 3 months ago

The correct method for converting a Time object to a DateTime object with TimeZone info is: datetime_obj = time_obj.to_datetime(datetime.UTC)