This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,7 @@
fansh> d := DateTime.fromLocale("March 7 2009 7:30pm EST", "MMMM D YYYY h:mmaa zzz")
fansh> d
2009-03-07T19:30:00-05:00 EST
fansh> d + 12hr
2009-03-08T07:30:00-05:00 EST
fansh> (d+12hr).toTimeZone(TimeZone("London")) // the extra credit!
2009-03-08T12:30:00Z London

View file

@ -0,0 +1,4 @@
### MMM dd yyyy h:mma ###
d = parseDate["March 7 2009 7:30pm EST"]
println[d + 12 hours -> Eastern]
println[d + 12 hours -> Switzerland] // Extra credit

View file

@ -0,0 +1,12 @@
import org.joda.time.*
import java.text.*
def dateString = 'March 7 2009 7:30pm EST'
def sdf = new SimpleDateFormat('MMMM d yyyy h:mma zzz')
DateTime dt = new DateTime(sdf.parse(dateString))
println (dt)
println (dt.plusHours(12))
println (dt.plusHours(12).withZone(DateTimeZone.UTC))

View file

@ -0,0 +1,10 @@
CHARACTER date="March 7 2009 7:30pm EST", am_pm, result*20
EDIT(Text=date, Parse=cMonth, GetPosition=next)
month = 1 + EDIT(Text='January,February,March,April,May,June,July,August,September,October,November,December', Right=cMonth, Count=',' )
READ(Text=date(next:)) day, year, hour, minute, am_pm
hour = hour + 12*(am_pm == 'p')
TIME(MOnth=month, Day=day, Year=year, Hour=hour, MInute=minute, TO, Excel=xls_day)
WRITE(Text=result, Format="UWWW CCYY-MM-DD HH:mm") xls_day + 0.5
! result = "Sun 2009-03-08 07:30"
END

View file

@ -0,0 +1,66 @@
link datetime
procedure main()
write("input = ",s := "March 7 2009 7:30pm EST" )
write("+12 hours = ",SecToTZDateLine(s := TZDateLineToSec(s) + 12*3600,"EST"))
write(" = ",SecToTZDateLine(s,"UTC"))
write(" = ",SecToTZDateLine(s,"NST"))
end
procedure SecToTZDateLine(s,tz) #: returns dateline + time zone given seconds
return NormalizedDate(SecToDateLine(s+\(_TZdata("table")[\tz|"UTC"]))||" "|| tz)
end
procedure TZDateLineToSec(s) #: returns seconds given dateline (and time zone)
return (
NormalizedDate(s) ? (
d := tab(find("am"|"pm")+2),tab(many('\t ,')),
tz := \_TZdata("table")[tab(0)]
),
DateLineToSec(d) - tz)
end
procedure NormalizedDate(s) #: returns a consistent dateline
static D,M
initial {
D := ["Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"]
M := ["January","February","March","April","May","June",
"July","August","September","October","November","December"]
}
map(s) ? { # parse and build consistent dateline
ds := 1(x := !D, =map(x)) | "" # Weekday
ds ||:= 1(", ", tab(many('\t ,')|&pos))
ds ||:= 1(x := !M, =map(x)) | fail # Month
ds ||:= 1(" ", tab(many('\t ,')|&pos))
ds ||:= tab(many(&digits)) | fail # day
ds ||:= 1(", ", tab(many('\t ,'))) | fail
ds ||:= tab(many(&digits)) | fail # year
ds ||:= 1(" ", tab(many('\t ,'))) | fail
ds ||:= tab(many(&digits))||(=":"||tab(many(&digits))|&null) | fail # time
ds ||:= 1(" ", tab(many('\t ,')|&pos))
ds ||:= =("am"|"pm") | fail # halfday
ds ||:= 1(" ", tab(many('\t ,')|&pos))
tz := map(=!_TZdata("list"),&lcase,&ucase)
}
if ds[1] == "," then
ds := SecToDateLine(DateLineToSec("Sunday"||ds)) # get IPL to fix weekday
return ds ||:= " " || \tz|"UTC"
end
procedure _TZdata(x) #: internal return TZ data (demo version incomplete)
static TZ,AZ
initial {
TZ := table()
AZ := []
"UTC/0;ACDT/+10.5;CET/1;EST/-5;NPT/+5.75;NST/-3.5;PST/-8;" ?
while ( a := tab(find("/")), move(1), o := tab(find(";")), move(1) ) do {
TZ[map(a)] := TZ[a] := integer(3600*o)
put(AZ,a,map(a))
}
every TZ[&null|""] := TZ["UTC"]
}
return case x of { "list" : AZ ; "table" : TZ }
end

View file

@ -0,0 +1,2 @@
dstr = "March 7 2009 7:30pm EST";
DateString[DatePlus[dstr, {12, "Hour"}], {"DayName", " ", "MonthName", " ", "Day", " ", "Year", " ", "Hour24", ":", "Minute", "AMPM"}]