Bug - Date Library

Not sure why, but it works fine if you actually pass on the timezone info:

:- use_module(library(date)).

get_dt(Datestring, Y, M, D, H, Mn, S, X) :-
    parse_time(Datestring, Stamp1),
    stamp_date_time(Stamp1, DateTime1, 'UTC'),
    DateTime1 = date(Y1, M1, D1, H1, Mn1, S1, Off, TZ, DST),
    S2 is S1 + X,
    date_time_stamp(date(Y1, M1, D1, H1, Mn1, S2, Off, TZ, DST), Stamp2),
    stamp_date_time(Stamp2, DateTime2, 'UTC'),
    DateTime2 = date(Y, M, D, H, Mn, S, _, _, _).
?- get_dt('2020-03-04 06:22:59.012315131', Y, M, D, H, Mn, S, 1).
Y = 2020,
M = 3,
D = 4,
H = 6,
Mn = 23,
S = 0.012315034.

Surely passing on is a good idea. I’m afraid I do not have time right now to figure out what exactly is supposed to happen if you pass variables.

Surely if you want to compute second offsets, doing so based on the time stamp is a lot easier. The non-normalized values for the time stamp are useful if you want to change a date by a month or a year as these do not have a defined number of seconds.

2 Likes