46 lines
1.5 KiB
Text
46 lines
1.5 KiB
Text
$ include "seed7_05.s7i";
|
|
include "time.s7i";
|
|
include "duration.s7i";
|
|
|
|
const func time: parseDate (in string: dateStri) is func
|
|
result
|
|
var time: aTime is time.value;
|
|
local
|
|
const array string: monthNames is [] ("January", "February", "March", "April",
|
|
"May", "June", "July", "August", "September", "October", "November", "December");
|
|
var array string: dateParts is 0 times "";
|
|
var integer: month is 0;
|
|
var string: timeStri is "";
|
|
begin
|
|
dateParts := split(dateStri, ' ');
|
|
aTime.year := integer parse (dateParts[3]);
|
|
aTime.month := 1;
|
|
while monthNames[aTime.month] <> dateParts[1] do
|
|
incr(aTime.month);
|
|
end while;
|
|
aTime.day := integer parse (dateParts[2]);
|
|
timeStri := dateParts[4];
|
|
if endsWith(timeStri, "am") then
|
|
aTime.hour := integer parse (timeStri[.. pred(pos(timeStri, ':'))]);
|
|
elsif endsWith(timeStri, "pm") then
|
|
aTime.hour := integer parse (timeStri[.. pred(pos(timeStri, ':'))]) + 12;
|
|
else
|
|
raise RANGE_ERROR;
|
|
end if;
|
|
aTime.minute := integer parse (timeStri[succ(pos(timeStri, ':')) .. length(timeStri) - 2]);
|
|
if dateParts[5] <> "UTC" then
|
|
aTime.timeZone := 60 * integer parse (dateParts[5][4 ..]);
|
|
end if;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var time: aTime is time.value;
|
|
begin
|
|
aTime := parseDate("March 7 2009 7:30pm UTC-05");
|
|
writeln("Given: " <& aTime);
|
|
aTime +:= 1 . DAYS;
|
|
writeln("A day later: " <& aTime);
|
|
aTime := toUTC(aTime);
|
|
writeln("In UTC: " <& aTime);
|
|
end func;
|