RosettaCodeData/Task/Date-manipulation/MiniScript/date-manipulation.mini

35 lines
962 B
Plaintext

import "dateTime"
import "stringUtil"
months = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
]
date = "March 7 2009 7:30pm EST"
print "Original date/time : " + date
// change the date to standard format
items = date.split
month = months.indexOf(items[0]) + 1
day = items[1]
year = items[2]
time = items[3]
hour = time.split(":")[0].val
minute = time.split(":")[1][0:2]
pm = time.endsWith("pm")
if pm then hour = hour + 12
time = hour + ":" + minute
zone = items[4]
date = year + "-" + month + "-" + day + " " + time
// add 12 hours and display in original format
dval = dateTime.val(date) + 12*60*60
dfmt = "MMMM d yyyy h:mmtt"
date2 = dateTime.str(dval, dfmt) + " " + zone
print "12 hours later : " + date2
// change from EST to MST (2 hours earlier)
date3 = dateTime.str(dval - 2*60*60, dfmt) + " MST"
print "Adjusted to MST : " + date3