Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Date-manipulation/Seed7/date-manipulation.seed7
Normal file
46
Task/Date-manipulation/Seed7/date-manipulation.seed7
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
$ 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue