langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,29 @@
/* NetRexx */
options replace format comments java crossref symbols binary
import java.text.SimpleDateFormat
import java.text.ParseException
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method manipulateDate(sampleDate, dateFmt, dHours = 0) private static
formatter = SimpleDateFormat(dateFmt)
msHours = dHours * 60 * 60 * 1000 -- hours in milliseconds
day = formatter.parse(sampleDate)
day.setTime(day.getTime() + msHours)
formatted = formatter.format(day)
return formatted
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
do
sampleDate = 'March 7 2009 7:30pm EST'
dateFmt = "MMMM d yyyy h:mma z"
say sampleDate
say manipulateDate(sampleDate, dateFmt, 12)
catch ex = Exception
ex.printStackTrace()
end
return

View file

@ -0,0 +1,8 @@
/* The PL/I date functions handle dates and time in 49 */
/* different formats, but not that particular one. For any of the */
/* standard formats, the following date manipulation will add */
/* 12 hours to the current date/time. */
seconds = SECS(DATETIME());
seconds = seconds + 12*60*60;
put list (SECSTODATE(secs));

View file

@ -0,0 +1,2 @@
> (Calendar.dwim_time("March 7 2009 7:30pm EST")+Calendar.Hour()*12)->set_timezone("CET")->format_ext_time();
Result: "Saturday, 7 March 2009 12:30:00"

View file

@ -0,0 +1,4 @@
$date = [DateTime]::Parse("March 7 2009 7:30pm -5" )
write-host $date
write-host $date.AddHours(12)
write-host [TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($date.AddHours(12),"Vladivostok Standard Time")

View file

@ -0,0 +1,26 @@
REBOL [
Title: "Date Manipulation"
Author: oofoe
Date: 2009-12-06
URL: http://rosettacode.org/wiki/Date_Manipulation
]
; Only North American zones here -- feel free to extend for your area.
zones: [
NST -3:30 NDT -2:30 AST -4:00 ADT -3:00 EST -5:00 EDT -4:00
CST -6:00 CDT -5:00 MST -7:00 MDT -6:00 PST -8:00 PDT -7:00 AKST -9:00
AKDT -8:00 HAST -10:00 HADT -9:00]
read-time: func [
text
/local m d y t z
][
parse load text [
set m word! (m: index? find system/locale/months to-string m)
set d integer! set y integer!
set t time! set tz word!]
to-date reduce [y m d t zones/:tz]
]
print 12:00 + read-time "March 7 2009 7:30pm EST"

View file

@ -0,0 +1,18 @@
theDate$ = "March 7 2009 7:30pm EST"
monthName$ = "January February March April May June July August September October November December"
for i = 1 to 12
if word$(theDate$,1) = word$(monthName$,i) then monthNum = i ' turn month name to number
next i
d = val(date$(monthNum;"/";word$(theDate$,2);"/";word$(theDate$,3))) ' days since Jan 1 1901
t$ = word$(theDate$,4) ' get time from theDate$
t1$ = word$(t$,1,"pm") ' strip pm
t2$ = word$(t1$,1,":") + "." + word$(t1$,2,":") ' replace : with .
t = val(t2$)
if right$(t$,2) = "pm" then t = t + 12
ap$ = "pm"
if t + 12 > 24 then
d = d + 1 ' if over 24 hours add 1 to days since 1/1/1901
ap$ = "am"
end if
print date$(d);" ";t1$;ap$

View file

@ -0,0 +1,46 @@
$ include "seed7_05.s7i";
include "time.s7i";
include "duration.s7i";
const func time: parseDate (in string: dateStri) is func
result
var time: result is time.value;
local
const array string: monthNames is [] ("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November", "December");
var array string: dateParts is 0 times "";
var integer: month is 0;
var string: timeStri is "";
begin
dateParts := split(dateStri, ' ');
result.year := integer parse (dateParts[3]);
result.month := 1;
while monthNames[result.month] <> dateParts[1] do
incr(result.month);
end while;
result.day := integer parse (dateParts[2]);
timeStri := dateParts[4];
if endsWith(timeStri, "am") then
result.hour := integer parse (timeStri[.. pred(pos(timeStri, ':'))]);
elsif endsWith(timeStri, "pm") then
result.hour := integer parse (timeStri[.. pred(pos(timeStri, ':'))]) + 12;
else
raise RANGE_ERROR;
end if;
result.minute := integer parse (timeStri[succ(pos(timeStri, ':')) .. length(timeStri) - 2]);
if dateParts[5] <> "UTC" then
result.timeZone := 60 * integer parse (dateParts[5][4 ..]);
end if;
end func;
const proc: main is func
local
var time: aTime is time.value;
begin
aTime := parseDate("March 7 2009 7:30pm UTC-05");
writeln("Given: " <& aTime);
aTime +:= 1 . DAYS;
writeln("A day later: " <& aTime);
aTime := toUTC(aTime);
writeln("In UTC: " <& aTime);
end func;

View file

@ -0,0 +1 @@
date -d 'March 7 2009 7:30pm EST +12 hours'