Some examples as test cases for stamp_date_time/3 to help in understanding how it works

Created these test cases to help me further understand how to use stamp_date_time/3.

The SWI-Prolog implementation (source code) (test)

Sorry that the code is larger than allowed here, so please cut and paste it into a local editor to better see it all. :slightly_frowning_face:


:- begin_tests(stamp_date_time).

% GitHub SWI-Prolog library date:    https://github.com/SWI-Prolog/swipl-devel/blob/10f258f755beaffecd66f488769f154be028a8ca/library/date.pl
% GitHub SWI-Prolog date test cases: https://github.com/SWI-Prolog/swipl-devel/blob/10f258f755beaffecd66f488769f154be028a8ca/src/Tests/library/test_date.pl

test(001) :-
    current_prolog_flag(timezone,Timezone),
    assertion( Timezone == 18000 ).

% setlocale/3 has no effect on stamp_date_time/3 that I am aware.
test(002) :-
    setlocale(time,Current,Current),
    assertion( Current == 'English_United States.1252' ).

%                              Timestamp - See comment at end of each test line on how it was generated
%                              |                  TimeZone value for stamp_date_time(_,_,+TimeZone)      % Allowed values: local, 'UTC', 0   Not allowed: '-', 'Z'
%                              |                  |      Expected value from stamp_date_time(_,date(_,_,_,_,_,_,Offset,_,_),_)
%                              |                  |      |                 Expected value from stamp_date_time(_,date(Year,Month,Day,Hour,Minute,Seconds,Offset,Timezone_name,Daylight_savings_time),_)
%                              |                  |      |                 |    Year
%                              |                  |      |                 |    |     Month
%                              |                  |      |                 |    |     |   Day
%                              |                  |      |                 |    |     |   |   Hour
%                              |                  |      |                 |    |     |   |   |   Minute
%                              |                  |      |                 |    |     |   |   |   |   Seconds
%                              |                  |      |                 |    |     |   |   |   |   |                  Offset
%                              |                  |      |                 |    |     |   |   |   |   |                  |      Timezone name
%                              |                  |      |                 |    |     |   |   |   |   |                  |      |                        Daylight savings time
stamp_date_time_test_generator(1578843872.541233, local, current_timezone, date(2020,  1, 12, 10, 44, 32.54123306274414, 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?- get_time(Stamp).
stamp_date_time_test_generator(1578843872.541233, 'UTC',                0, date(2020,  1, 12, 15, 44, 32.541233062     ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?- get_time(Stamp).
stamp_date_time_test_generator(1578843872.541233,     0,                0, date(2020,  1, 12, 15, 44, 32.541233062     ,     0, -                      ,     - ) ).   % Timestamp created with ?- get_time(Stamp).

stamp_date_time_test_generator(946702800.0      , local, current_timezone, date(2000,  1,  1,  0,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?- current_prolog_flag(timezone,Offset),date_time_stamp(date(2000,1,1,0,0,0,Offset ,-    ,-),Stamp).
stamp_date_time_test_generator(946702800.0      , local, current_timezone, date(2000,  1,  1,  0,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,local,-),Stamp).
stamp_date_time_test_generator(946702800.0      , local, current_timezone, date(2000,  1,  1,  0,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'UTC',-),Stamp).
stamp_date_time_test_generator(946702800.0      , local, current_timezone, date(2000,  1,  1,  0,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'Z'  ,-),Stamp).
stamp_date_time_test_generator(946684800.0      , local, current_timezone, date(1999, 12, 31, 19,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,-    ,-),Stamp).
stamp_date_time_test_generator(946684800.0      , local, current_timezone, date(1999, 12, 31, 19,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,local,-),Stamp).
stamp_date_time_test_generator(946684800.0      , local, current_timezone, date(1999, 12, 31, 19,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'UTC',-),Stamp).
stamp_date_time_test_generator(946684800.0      , local, current_timezone, date(1999, 12, 31, 19,  0,  0.0             , 18000, 'Eastern Standard Time', false ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'Z'  ,-),Stamp).

stamp_date_time_test_generator(946702800.0      , 'UTC',                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?- current_prolog_flag(timezone,Offset),date_time_stamp(date(2000,1,1,0,0,0,Offset ,-    ,-),Stamp).
stamp_date_time_test_generator(946702800.0      , 'UTC',                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,local,-),Stamp).
stamp_date_time_test_generator(946702800.0      , 'UTC',                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'UTC',-),Stamp).
stamp_date_time_test_generator(946702800.0      , 'UTC',                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'Z'  ,-),Stamp).
stamp_date_time_test_generator(946684800.0      , 'UTC',                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,-    ,-),Stamp).
stamp_date_time_test_generator(946684800.0      , 'UTC',                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,local,-),Stamp).
stamp_date_time_test_generator(946684800.0      , 'UTC',                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'UTC',-),Stamp).
stamp_date_time_test_generator(946684800.0      , 'UTC',                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, 'UTC'                  ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'Z'  ,-),Stamp).

stamp_date_time_test_generator(946702800.0      ,     0,                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?- current_prolog_flag(timezone,Offset),date_time_stamp(date(2000,1,1,0,0,0,Offset ,-    ,-),Stamp).
stamp_date_time_test_generator(946702800.0      ,     0,                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,local,-),Stamp).
stamp_date_time_test_generator(946702800.0      ,     0,                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'UTC',-),Stamp).
stamp_date_time_test_generator(946702800.0      ,     0,                0, date(2000,  1,  1,  5,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,Offset ,'Z'  ,-),Stamp).
stamp_date_time_test_generator(946684800.0      ,     0,                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,-    ,-),Stamp).
stamp_date_time_test_generator(946684800.0      ,     0,                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,local,-),Stamp).
stamp_date_time_test_generator(946684800.0      ,     0,                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'UTC',-),Stamp).
stamp_date_time_test_generator(946684800.0      ,     0,                0, date(2000,  1,  1,  0,  0,  0.0             ,     0, -                      ,     - ) ).   % Timestamp created with ?-                                      date_time_stamp(date(2000,1,1,0,0,0,0      ,'Z'  ,-),Stamp).

test(005,[forall(stamp_date_time_test_generator(Timestamp,Stamp_timezone,Expected_offset,Expected_date_time))]) :-
    % format('~nTimestamp: ~w~n',[Timestamp]),
    stamp_date_time(Timestamp,Date_time,Stamp_timezone),
    % format('Date_time: ~w~n',[Date_time]),
    % Date_time = date(Year,Month,Day,Hour,Minute,Seconds,Offset,Timezone_name,Daylight_savings_time),
    Date_time = date(_,_,_,_,_,_,Offset,_,_),
    (
        Expected_offset == current_timezone
    ->
        current_prolog_flag(timezone,Current_timezone),
        assertion( Offset == Current_timezone )
    ;
        assertion( Offset == Expected_offset )
    ),
    assertion( Date_time == Expected_date_time ).

:- end_tests(stamp_date_time).

Running of tests.

?- run_tests(stamp_date_time).
% PL-Unit: stamp_date_time ............................. done
% All 29 tests passed
true.