@@ -197,7 +197,13 @@ def _get_rc_timezone():
197
197
Time-related constants.
198
198
"""
199
199
EPOCH_OFFSET = float (datetime .datetime (1970 , 1 , 1 ).toordinal ())
200
- JULIAN_OFFSET = 1721424.5 # Julian date at 0001-01-01
200
+ # EPOCH_OFFSET is not used by matplotlib
201
+ JULIAN_OFFSET = 1721424.5 # Julian date at 0000-12-31
202
+ # note that the Julian day epoch is achievable w/
203
+ # np.datetime64('-4713-11-24T12:00:00'); datetime64 is proleptic
204
+ # Gregorian and BC has a one-year offset. So
205
+ # np.datetime64('0000-12-31') - np.datetime64('-4713-11-24T12:00') = 1721424.5
206
+ # Ref: https://en.wikipedia.org/wiki/Julian_day
201
207
MICROSECONDLY = SECONDLY + 1
202
208
HOURS_PER_DAY = 24.
203
209
MIN_PER_HOUR = 60.
@@ -445,14 +451,20 @@ def julian2num(j):
445
451
Parameters
446
452
----------
447
453
j : float or sequence of floats
448
- Julian date(s)
454
+ Julian dates (days relative to 4713 BC Jan 1, 12:00:00 Julian
455
+ calendar or 4714 BC Nov 24, 12:00:00, proleptic Gregorian calendar).
449
456
450
457
Returns
451
458
-------
452
459
float or sequence of floats
453
- Matplotlib date(s)
460
+ Matplotlib dates (days relative to `.get_epoch`).
454
461
"""
455
- return np .subtract (j , JULIAN_OFFSET ) # Handles both scalar & nonscalar j.
462
+ ep = np .datetime64 (get_epoch (), 'h' ).astype (float ) / 24.
463
+ ep0 = np .datetime64 ('0000-12-31T00:00:00' , 'h' ).astype (float ) / 24.
464
+ # Julian offset defined above is relative to 0000-12-31, but we need
465
+ # relative to our current epoch:
466
+ dt = JULIAN_OFFSET - ep0 + ep
467
+ return np .subtract (j , dt ) # Handles both scalar & nonscalar j.
456
468
457
469
458
470
def num2julian (n ):
@@ -462,14 +474,19 @@ def num2julian(n):
462
474
Parameters
463
475
----------
464
476
n : float or sequence of floats
465
- Matplotlib date(s)
477
+ Matplotlib date s (days relative to `.get_epoch`).
466
478
467
479
Returns
468
480
-------
469
481
float or sequence of floats
470
- Julian date(s)
471
- """
472
- return np .add (n , JULIAN_OFFSET ) # Handles both scalar & nonscalar j.
482
+ Julian dates (days relative to 4713 BC Jan 1, 12:00:00).
483
+ """
484
+ ep = np .datetime64 (get_epoch (), 'h' ).astype (float ) / 24.
485
+ ep0 = np .datetime64 ('0000-12-31T00:00:00' , 'h' ).astype (float ) / 24.
486
+ # Julian offset defined above is relative to 0000-12-31, but we need
487
+ # relative to our current epoch:
488
+ dt = JULIAN_OFFSET - ep0 + ep
489
+ return np .add (n , dt ) # Handles both scalar & nonscalar j.
473
490
474
491
475
492
def num2date (x , tz = None ):
0 commit comments