RosettaCodeData/Task/Date-manipulation/Lingo/date-manipulation-2.lingo

28 lines
757 B
Plaintext

dateStr = "March 7 2009 7:30pm EST"
-- parse string
month = (offset(dateStr.word[1].char[1..3], "JanFebMarAprMayJunJulAugSepOctNovDec")-1)/3 + 1
day = integer(dateStr.word[2])
year = integer(dateStr.word[3])
t = dateStr.word[4]
if t.char[t.length-1..t.length]="pm" then dh = 12
else dh = 0
t = t.char[1..t.length-2]
_player.itemDelimiter = ":"
hour = integer(t.item[1])+dh
minute = integer(t.item[2])
tz = dateStr.word[5] -- unused
-- original date as date object
dateObj = date(year,month,day)
dateObj.seconds = hour*3600 + minute*60
-- add 12 hours
sec = dateObj.seconds + 12*3600
newDateObj = dateObj + sec / 86400
newDateObj.seconds = sec mod 86400
-- show as YYYY-MM-DD hh:mm:ii string
put dateToDateTimeString(newDateObj)
-- "2009-03-08 07:30:00"