Julian date of timezone-aware timestamp?

47 Views Asked by At

Should the Julian date change depending on the original timestamp's time zone?

For example, do 2020-01-01 +00:00 and 2020-01-01 +05:45 have the same Julian Date?

pandas suggests they do:

In [1]: import pandas as pd

In [2]: pd.Timestamp('2020-01-01', tz='Europe/London').to_julian_date()
Out[2]: 2458849.5

In [3]: pd.Timestamp('2020-01-01', tz='Asia/Kathmandu').to_julian_date()
Out[3]: 2458849.5

Is this a bug in pandas?

1

There are 1 best solutions below

6
Corralien On

It seems julian date implementation doesn't care about the timezone

>>> pd.Timestamp('2020-01-01').to_julian_date()
2458849.5

>>> pd.Timestamp('2020-01-01', tz='UTC').to_julian_date()
2458849.5

>>> pd.Timestamp('2020-01-01', tz='Europe/London').to_julian_date()
2458849.5

>>> pd.Timestamp('2020-01-01', tz='Asia/Kathmandu').to_julian_date()
2458849.5

>>> pd.Timestamp('2020-01-01', tz='Asia/Kathmandu').tz_localize(None).to_julian_date()
2458849.5

If you want to take timezone into account, you have to handle it yourself:

>>> pd.Timestamp('2020-01-01', tz='Asia/Kathmandu').tz_convert('UTC').to_julian_date()
2458849.2604166665

Is it correct that pandas is ignoring tz here?

The method to_julian_date() ignore tz:

class Timestamp(_Timestamp):
    ...
    def to_julian_date(self) -> np.float64:
        ...
        year = self.year
        month = self.month
        day = self.day
        if month <= 2:
            year -= 1
            month += 12
        return (day +
                np.fix((153 * month - 457) / 5) +
                365 * year +
                np.floor(year / 4) -
                np.floor(year / 100) +
                np.floor(year / 400) +
                1721118.5 +
                (self.hour +
                 self.minute / 60.0 +
                 self.second / 3600.0 +
                 self.microsecond / 3600.0 / 1e+6 +
                 self.nanosecond / 3600.0 / 1e+9
                 ) / 24.0)