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,4 @@
USING: formatting calendar io ;
now "%Y-%m-%d" strftime print
now "%A, %B %d, %Y" strftime print

View file

@ -0,0 +1,4 @@
fansh> Date.today.toLocale("YYYY-MM-DD")
2011-02-24
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY")
Thursday, February 24, 2011

View file

@ -0,0 +1,2 @@
println[now[] -> ### yyyy-MM-dd ###]
println[now[] -> ### EEEE, MMMM d, yyyy ###]

View file

@ -0,0 +1,2 @@
def isoFormat = { date -> date.format("yyyy-MM-dd") }
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }

View file

@ -0,0 +1,3 @@
def now = new Date()
println isoFormat(now)
println longFormat(now)

View file

@ -0,0 +1,13 @@
CHARACTER string*40
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13
! the U-format to write date and time uses ',' to separate additional output formats
! we therefore use ';' in this example and change it to ',' below:
WRITE(Text=string,Format='UWWWWWWWWW; MM DD; CCYY') 0 ! string = "Saturday ; 03 13; 2010"
READ(Text=string) month ! first numeric value = 3 (no literal month name available)
EDIT(Text='January,February,March,April,May,June,July,August,September,October,November,December', ITeM=month, Parse=cMonth) ! cMonth = "March"
! change now string = "Saturday ; 03 13; 2010" to "Saturday, March 13, 2010":
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',')
END

View file

@ -0,0 +1,4 @@
procedure main()
write(map(&date,"/","-"))
write(&dateline ? tab(find(&date[1:5])+4))
end

View file

@ -0,0 +1,2 @@
6!:0 'YYYY-MM-DD'
2010-08-19

View file

@ -0,0 +1,6 @@
require 'dates system/packages/misc/datefmt.ijs'
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.]
fmtDate 6!:0 ''
Thursday, August 19, 2010

View file

@ -0,0 +1,9 @@
DEFINE weekdays == [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ];
months == [ "January" "February" "March" "April" "May" "June" "July" "August"
"September" "October" "November" "December" ].
time localtime [ [0 at 'd 4 4 format] ["-"] [1 at 'd 2 2 format] ["-"] [2 at 'd 2 2 format] ]
[i] map [putchars] step '\n putch pop.
time localtime [ [8 at pred weekdays of] [", "] [1 at pred months of] [" "] [2 at 'd 1 1 format]
[", "] [0 at 'd 4 4 format] ] [i] map [putchars] step '\n putch pop.

View file

@ -0,0 +1,23 @@
'Display the current date in the formats of "2007-11-10"
d$=date$("yyyy/mm/dd")
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/")
'and "Sunday, November 10, 2007".
day$(0)="Tuesday"
day$(1)="Wednesday"
day$(2)="Thursday"
day$(3)="Friday"
day$(4)="Saturday"
day$(5)="Sunday"
day$(6)="Monday"
theDay = date$("days") mod 7
print day$(theDay);", ";date$()
' month in full
year=val(word$(d$,1,"/"))
month=val(word$(d$,2,"/"))
day=val(word$(d$,3,"/"))
weekDay$="Tuesday Wednesday Thursday Friday Saturday Sunday Monday"
monthLong$="January February March April May June July August September October November December"
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year

View file

@ -0,0 +1,4 @@
DTZ
WRITE !,"Date format 3: ",$ZDATE($H,3)
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9)
QUIT

View file

@ -0,0 +1,21 @@
DTM(H)
;You can pass an integer, but the default is to use today's value
SET:$DATA(H)=0 H=$HOROLOG
NEW Y,YR,RD,MC,MO,DA,MN,DN,DOW
SET MN="January,February,March,April,May,June,July,August,September,October,November,December"
SET DN="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
SET MC="31,28,31,30,31,30,31,31,30,31,30,31"
SET Y=+H\365.25 ;This shouldn't be an approximation in production code
SET YR=Y+1841 ;Y is the offset from the epoch in years
SET RD=((+H-(Y*365.25))+1)\1 ;How far are we into the year?
SET $P(MC,",",2)=$S(((YR#4=0)&(YR#100'=0))!((YR#100=0)&(YR#400=0))=0:28,1:29) ;leap year correction
SET MO=1,RE=RD FOR QUIT:RE<=$P(MC,",",MO) SET RE=RE-$P(MC,",",MO),MO=MO+1
SET DA=RE+1
SET DOW=(H#7)+5 ;Fencepost issue - the first piece is 1
;add padding as needed
SET:$L(MO)<2 MO="0"_MO
SET:$L(DA)<2 DA="0"_DA
WRITE !,YR,"-",MO,"-",DA
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW
QUIT

View file

@ -0,0 +1,2 @@
DateString[{"Year", "-", "Month", "-", "Day"}]
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]