langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
29
Task/Date-manipulation/NetRexx/date-manipulation.netrexx
Normal file
29
Task/Date-manipulation/NetRexx/date-manipulation.netrexx
Normal 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
|
||||
8
Task/Date-manipulation/PL-I/date-manipulation.pli
Normal file
8
Task/Date-manipulation/PL-I/date-manipulation.pli
Normal 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));
|
||||
2
Task/Date-manipulation/Pike/date-manipulation.pike
Normal file
2
Task/Date-manipulation/Pike/date-manipulation.pike
Normal 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"
|
||||
4
Task/Date-manipulation/PowerShell/date-manipulation.psh
Normal file
4
Task/Date-manipulation/PowerShell/date-manipulation.psh
Normal 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")
|
||||
26
Task/Date-manipulation/REBOL/date-manipulation.rebol
Normal file
26
Task/Date-manipulation/REBOL/date-manipulation.rebol
Normal 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"
|
||||
18
Task/Date-manipulation/Run-BASIC/date-manipulation.run
Normal file
18
Task/Date-manipulation/Run-BASIC/date-manipulation.run
Normal 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$
|
||||
46
Task/Date-manipulation/Seed7/date-manipulation.seed7
Normal file
46
Task/Date-manipulation/Seed7/date-manipulation.seed7
Normal 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;
|
||||
1
Task/Date-manipulation/UNIX-Shell/date-manipulation.sh
Normal file
1
Task/Date-manipulation/UNIX-Shell/date-manipulation.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
date -d 'March 7 2009 7:30pm EST +12 hours'
|
||||
Loading…
Add table
Add a link
Reference in a new issue