The conversion works in both directions. If the UnixTime argument is instantiated, it gets converted to the local date and time, and the first 6 arguments get unified accordingly.
If the first 6 (or 7) arguments are instantiated, they will be interpreted under the current time zone and daylight savings time rules, and converted into 'Unix time', which is unified with the last argument.
In both directions, the DST argument can usually remain uninstantiated, and will be unified with 1 if the date specified is while daylight savings time is in effect, and 0 otherwise. Note however, that during the switch from summer to winter time, there is usually a one hour overlap, where the same time of day exists twice, once in summer and once in winter time. In this case, when converting from local time to UTC, the caller should instantiate DST in order to disambiguate.
The predicate can also be used to test for valid local date and time: If the first 6 (or 7) arguments do not represent a valid date, the predicate fails.
This predicate is based on the POSIX localtime() and mktime() functions.
?- get_flag(unix_time,T), local_time(Yr,Mo,Dy,Hr,Mi,Sc,Ds,T). Yr = 2003 Mo = 4 Dy = 4 Hr = 16 Mi = 38 Sc = 30 Ds = 1 T = 1049470710 Yes (0.00s cpu) ?- local_time(2003,4,4,16,38,30,1,T). T = 1049470710 Yes (0.00s cpu) ?- local_time(2003,4,4,16,38,30,_,T). T = 1049470710 Yes (0.00s cpu) ?- local_time(2003,1,1,25,0,0,_,_). % invalid hour No (0.00s cpu) ?- local_time(2003,2,29,12,0,0,_,_). % invalid date (no leap year) No (0.00s cpu) % The following examples assume DST rules for Britain ?- local_time(2003,3,30,1,30,0,_,_). % invalid time (skipped hour) No (0.00s cpu) ?- local_time(2003,10,26,1,0,0,1,T). % 1h before end of summer time T = 1067126400 Yes (0.01s cpu) ?- local_time(2003,10,26,1,0,0,0,T). % 1 hour later T = 1067130000 Yes (0.00s cpu)