Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Date-manipulation/Lingo/date-manipulation-1.lingo
Normal file
35
Task/Date-manipulation/Lingo/date-manipulation-1.lingo
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
----------------------------------------
|
||||
-- Returns string representation of given date object in YYYY-MM-DD hh:mm:ii format
|
||||
-- @param {date} dateObj
|
||||
-- @returns {string}
|
||||
----------------------------------------
|
||||
on dateToDateTimeString (dateObj)
|
||||
str = ""
|
||||
s = string(dateObj.year)
|
||||
if s.length<4 then put "0000".char[1..4-s.length] before s
|
||||
put s after str
|
||||
s = string(dateObj.month)
|
||||
if s.length<2 then s = "0"&s
|
||||
put s after str
|
||||
s = string(dateObj.day)
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
sec = dateObj.seconds
|
||||
s = string(sec / 3600)
|
||||
sec = sec mod 3600
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
s = string(sec / 60)
|
||||
sec = sec mod 60
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
s = string(sec)
|
||||
if s.length<2 then put "0" before s
|
||||
put s after str
|
||||
put ":" after char 12 of str
|
||||
put ":" after char 10 of str
|
||||
put " " after char 8 of str
|
||||
put "-" after char 6 of str
|
||||
put "-" after char 4 of str
|
||||
return str
|
||||
end
|
||||
27
Task/Date-manipulation/Lingo/date-manipulation-2.lingo
Normal file
27
Task/Date-manipulation/Lingo/date-manipulation-2.lingo
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue