Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
97
Task/Date-manipulation/Ada/date-manipulation.adb
Normal file
97
Task/Date-manipulation/Ada/date-manipulation.adb
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
with Ada.Calendar;
|
||||
with Ada.Calendar.Formatting;
|
||||
with Ada.Calendar.Time_Zones;
|
||||
with Ada.Integer_Text_IO;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Date_Manipulation is
|
||||
|
||||
type Month_Name_T is
|
||||
(January, February, March, April, May, June,
|
||||
July, August, September, October, November, December);
|
||||
|
||||
type Time_Zone_Name_T is (EST, Lisbon);
|
||||
|
||||
type Period_T is (AM, PM);
|
||||
|
||||
package TZ renames Ada.Calendar.Time_Zones;
|
||||
use type TZ.Time_Offset;
|
||||
|
||||
Time_Zone_Offset : array (Time_Zone_Name_T) of TZ.Time_Offset :=
|
||||
(EST => -5 * 60,
|
||||
Lisbon => 0);
|
||||
|
||||
Period_Offset : array (Period_T) of Natural :=
|
||||
(AM => 0,
|
||||
PM => 12);
|
||||
|
||||
package Month_Name_IO is
|
||||
new Ada.Text_IO.Enumeration_IO (Month_Name_T);
|
||||
|
||||
package Time_Zone_Name_IO is
|
||||
new Ada.Text_IO.Enumeration_IO (Time_Zone_Name_T);
|
||||
|
||||
package Period_IO is
|
||||
new Ada.Text_IO.Enumeration_IO (Period_T);
|
||||
|
||||
package Std renames Ada.Calendar;
|
||||
use type Std.Time;
|
||||
|
||||
package Fmt renames Std.Formatting;
|
||||
|
||||
function To_Number (Name : Month_Name_T) return Std.Month_Number is
|
||||
begin
|
||||
return Std.Month_Number (Month_Name_T'Pos (Name) + 1);
|
||||
end;
|
||||
|
||||
function To_Time (S : String) return Std.Time is
|
||||
Month : Month_Name_T;
|
||||
Day : Std.Day_Number;
|
||||
Year : Std.Year_Number;
|
||||
Hour : Fmt.Hour_Number;
|
||||
Minute : Fmt.Minute_Number;
|
||||
Period : Period_T;
|
||||
Time_Zone : Time_Zone_Name_T;
|
||||
I : Natural;
|
||||
begin
|
||||
Month_Name_IO.Get
|
||||
(From => S, Item => Month, Last => I);
|
||||
Ada.Integer_Text_IO.Get
|
||||
(From => S (I + 1 .. S'Last), Item => Day, Last => I);
|
||||
Ada.Integer_Text_IO.Get
|
||||
(From => S (I + 1 .. S'Last), Item => Year, Last => I);
|
||||
Ada.Integer_Text_IO.Get
|
||||
(From => S (I + 1 .. S'Last), Item => Hour, Last => I);
|
||||
Ada.Integer_Text_IO.Get
|
||||
(From => S (I + 2 .. S'Last), Item => Minute, Last => I);
|
||||
-- here we start 2 chars down to skip the ':'
|
||||
Period_IO.Get
|
||||
(From => S (I + 1 .. S'Last), Item => Period, Last => I);
|
||||
Time_Zone_Name_IO.Get
|
||||
(From => S (I + 1 .. S'Last), Item => Time_Zone, Last => I);
|
||||
return Fmt.Time_Of
|
||||
(Year => Year,
|
||||
Month => To_Number (Month),
|
||||
Day => Day,
|
||||
Hour => Hour + Period_Offset (Period),
|
||||
Minute => Minute,
|
||||
Second => 0,
|
||||
Time_Zone => Time_Zone_Offset (Time_Zone));
|
||||
end;
|
||||
|
||||
function Img
|
||||
(Date : Std.Time; Zone : Time_Zone_Name_T) return String is
|
||||
begin
|
||||
return
|
||||
Fmt.Image (Date => Date, Time_Zone => Time_Zone_Offset (Zone)) &
|
||||
" " & Time_Zone_Name_T'Image (Zone);
|
||||
end;
|
||||
|
||||
T1, T2 : Std.Time;
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
T1 := To_Time ("March 7 2009 7:30pm EST");
|
||||
T2 := T1 + 12.0 * 60.0 * 60.0;
|
||||
Put_Line ("T1 => " & Img (T1, EST) & " = " & Img (T1, Lisbon));
|
||||
Put_Line ("T2 => " & Img (T2, EST) & " = " & Img (T2, Lisbon));
|
||||
end;
|
||||
121
Task/Date-manipulation/COBOL/date-manipulation.cob
Normal file
121
Task/Date-manipulation/COBOL/date-manipulation.cob
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
identification division.
|
||||
program-id. date-manipulation.
|
||||
|
||||
environment division.
|
||||
configuration section.
|
||||
repository.
|
||||
function all intrinsic.
|
||||
|
||||
data division.
|
||||
working-storage section.
|
||||
01 given-date.
|
||||
05 filler value z"March 7 2009 7:30pm EST".
|
||||
01 date-spec.
|
||||
05 filler value z"%B %d %Y %I:%M%p %Z".
|
||||
|
||||
01 time-struct.
|
||||
05 tm-sec usage binary-long.
|
||||
05 tm-min usage binary-long.
|
||||
05 tm-hour usage binary-long.
|
||||
05 tm-mday usage binary-long.
|
||||
05 tm-mon usage binary-long.
|
||||
05 tm-year usage binary-long.
|
||||
05 tm-wday usage binary-long.
|
||||
05 tm-yday usage binary-long.
|
||||
05 tm-isdst usage binary-long.
|
||||
05 tm-gmtoff usage binary-c-long.
|
||||
05 tm-zone usage pointer.
|
||||
01 scan-index usage pointer.
|
||||
|
||||
01 time-t usage binary-c-long.
|
||||
01 time-tm usage pointer.
|
||||
|
||||
01 reform-buffer pic x(64).
|
||||
01 reform-length usage binary-long.
|
||||
|
||||
01 current-locale usage pointer.
|
||||
|
||||
01 iso-spec constant as "YYYY-MM-DDThh:mm:ss+hh:mm".
|
||||
01 iso-date constant as "2009-03-07T19:30:00-05:00".
|
||||
01 date-integer pic 9(9).
|
||||
01 time-integer pic 9(9).
|
||||
|
||||
procedure division.
|
||||
|
||||
call "strptime" using
|
||||
by reference given-date
|
||||
by reference date-spec
|
||||
by reference time-struct
|
||||
returning scan-index
|
||||
on exception
|
||||
display "error calling strptime" upon syserr
|
||||
end-call
|
||||
display "Given: " given-date
|
||||
|
||||
if scan-index not equal null then
|
||||
*> add 12 hours, and reform as local
|
||||
call "mktime" using time-struct returning time-t
|
||||
add 43200 to time-t
|
||||
perform form-datetime
|
||||
|
||||
*> reformat as Pacific time
|
||||
set environment "TZ" to "PST8PDT"
|
||||
call "tzset" returning omitted
|
||||
perform form-datetime
|
||||
|
||||
*> reformat as Greenwich mean
|
||||
set environment "TZ" to "GMT"
|
||||
call "tzset" returning omitted
|
||||
perform form-datetime
|
||||
|
||||
|
||||
*> reformat for Tokyo time, as seen in Hong Kong
|
||||
set environment "TZ" to "Japan"
|
||||
call "tzset" returning omitted
|
||||
call "setlocale" using by value 6 by content z"en_HK.utf8"
|
||||
returning current-locale
|
||||
on exception
|
||||
display "error with setlocale" upon syserr
|
||||
end-call
|
||||
move z"%c" to date-spec
|
||||
perform form-datetime
|
||||
else
|
||||
display "date parse error" upon syserr
|
||||
end-if
|
||||
|
||||
*> A more standard COBOL approach, based on ISO8601
|
||||
display "Given: " iso-date
|
||||
move integer-of-formatted-date(iso-spec, iso-date)
|
||||
to date-integer
|
||||
|
||||
move seconds-from-formatted-time(iso-spec, iso-date)
|
||||
to time-integer
|
||||
|
||||
add 43200 to time-integer
|
||||
if time-integer greater than 86400 then
|
||||
subtract 86400 from time-integer
|
||||
add 1 to date-integer
|
||||
end-if
|
||||
display " " substitute(formatted-datetime(iso-spec
|
||||
date-integer, time-integer, -300), "T", "/")
|
||||
|
||||
goback.
|
||||
|
||||
form-datetime.
|
||||
call "localtime" using time-t returning time-tm
|
||||
call "strftime" using
|
||||
by reference reform-buffer
|
||||
by value length(reform-buffer)
|
||||
by reference date-spec
|
||||
by value time-tm
|
||||
returning reform-length
|
||||
on exception
|
||||
display "error calling strftime" upon syserr
|
||||
end-call
|
||||
if reform-length > 0 and <= length(reform-buffer) then
|
||||
display " " reform-buffer(1 : reform-length)
|
||||
else
|
||||
display "date format error" upon syserr
|
||||
end-if
|
||||
.
|
||||
end program date-manipulation.
|
||||
40
Task/Date-manipulation/Emacs-Lisp/date-manipulation-1.el
Normal file
40
Task/Date-manipulation/Emacs-Lisp/date-manipulation-1.el
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
(defun fix-time-string (calendar-string)
|
||||
"If CALENDAR-STRING has no space between time and am/a.m./pm/p.m., add a space.
|
||||
Return string with space between time and am/a.m./pm/p.m."
|
||||
(replace-regexp-in-string "\\([[:digit:]]\\)\\([ap]\\)" "\\1 \\2" calendar-string))
|
||||
|
||||
(defun is-pm (calendar-string)
|
||||
"Test if CALENDAR-STRING has PM/pm/P.M/p.m in it."
|
||||
(string-match-p "[Pp][.]?[Mm]" calendar-string))
|
||||
|
||||
(defun is-hour-1-to-11 (a-calendar-list)
|
||||
"Test if hour in A-CALENDAR-LIST is between 1 and 11."
|
||||
(let ((hour-value))
|
||||
(setq hour-value (nth 2 a-calendar-list))
|
||||
(and (>= hour-value 1) (<= hour-value 11))))
|
||||
|
||||
(defun adjust-if-pm (time-as-string)
|
||||
"If TIME-AS-STRING includes pm/PM, and hour is 1 to 11, add 12 hours.
|
||||
Return CALENDAR-LIST modified if date is pm and hour is 1-11; otherwise
|
||||
return CALENDAR-LIST of original TIME-AS-STRING."
|
||||
(let ((calendar-list))
|
||||
(setq calendar-list (parse-time-string time-as-string))
|
||||
(if (and (is-pm time-as-string) (is-hour-1-to-11 calendar-list))
|
||||
(decoded-time-add calendar-list (make-decoded-time :hour 12))
|
||||
calendar-list)))
|
||||
|
||||
(defun add-hours (calendar-list number-of-hours)
|
||||
"Add NUMBER-OF-HOURS to CALENDAR-LIST."
|
||||
(decoded-time-add calendar-list (make-decoded-time :hour number-of-hours)))
|
||||
|
||||
(defun calc-future-time (string-calendar-date number-of-hours-in-future)
|
||||
"Calculate future time by adding NUMBER-OF-HOURS-IN-FUTURE to STRING-CALENDAR-DATE ."
|
||||
(let ((fixed-calendar-string)
|
||||
(24-hour-calendar-list)
|
||||
(calendar-list-future-time)
|
||||
(coded-future-time))
|
||||
(setq fixed-calendar-string (fix-time-string string-calendar-date))
|
||||
(setq 24-hour-calendar-list (adjust-if-pm fixed-calendar-string))
|
||||
(setq calendar-list-future-time (add-hours 24-hour-calendar-list number-of-hours-in-future))
|
||||
(setq coded-future-time (encode-time calendar-list-future-time))
|
||||
(format-time-string "%B %e %Y %R %p %Z" coded-future-time)))
|
||||
41
Task/Date-manipulation/Emacs-Lisp/date-manipulation-2.el
Normal file
41
Task/Date-manipulation/Emacs-Lisp/date-manipulation-2.el
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
(defun fix-time-string (calendar-string)
|
||||
"If CALENDAR-STRING has no space between time and a.m./p.m., add a space."
|
||||
(replace-regexp-in-string "\\([[:digit:]]\\)\\([ap]\\)" "\\1 \\2" calendar-string))
|
||||
|
||||
(defun is-pm (calendar-string)
|
||||
"Test if CALENDAR-STRING has PM/pm in it."
|
||||
(string-match-p "[Pp][Mm]" time-as-string))
|
||||
|
||||
(defun is-hour-1-to-11 (a-calendar-list)
|
||||
"Test if hour in A-CALENDAR-LIST is between 1 and 11."
|
||||
(let ((hour-value))
|
||||
(setq hour-value (nth 2 a-calendar-list))
|
||||
(and (>= hour-value 1) (<= hour-value 11))))
|
||||
|
||||
(defun adjust-if-pm (time-as-string)
|
||||
"If TIME-AS-STRING includes pm/PM, and hour is 1 to 11, add 12 hours.
|
||||
Return time as integer of seconds past the epoch."
|
||||
(let ((calendar-list)
|
||||
(temp-time-stamp)
|
||||
(time-stamp-as-integer))
|
||||
(setq calendar-list (parse-time-string time-as-string))
|
||||
(setq temp-time-stamp (encode-time calendar-list))
|
||||
(setq time-stamp-as-integer (time-convert temp-time-stamp 'integer))
|
||||
(if (and (is-pm time-as-string) (is-hour-1-to-11 calendar-list))
|
||||
(+ time-stamp-as-integer (* 12 60 60)) ; return time + 12 hours, so that hour is 13-23
|
||||
time-stamp-as-integer))) ; return time unchanged, leaving hour 0-12
|
||||
|
||||
(defun add-seconds (start-time-stamp-integer number-of-seconds)
|
||||
"Add NUMBER-OF-HOURS to START-TIME-STAMP-INTEGER."
|
||||
(+ start-time-stamp-integer number-of-seconds))
|
||||
|
||||
(defun calc-future-time (string-calendar-date number-of-seconds-in-future)
|
||||
"Calculate future time by adding NUMBER-OF-SECONDS-IN-FUTURE to STRING-CALENDAR-DATE ."
|
||||
(let ((fixed-calendar-string)
|
||||
(time-stamp-as-integer)
|
||||
(coded-current-time)
|
||||
(future-time-as-integer))
|
||||
(setq fixed-calendar-string (fix-time-string string-calendar-date))
|
||||
(setq time-stamp-as-integer (adjust-if-pm fixed-calendar-string))
|
||||
(setq future-time-as-integer (add-seconds time-stamp-as-integer number-of-seconds-in-future))
|
||||
(format-time-string "%B %e %Y %R %p %Z" future-time-as-integer)))
|
||||
10
Task/Date-manipulation/Euphoria/date-manipulation.eu
Normal file
10
Task/Date-manipulation/Euphoria/date-manipulation.eu
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
--Date Manipulation task from Rosetta Code wiki
|
||||
--User:Lnettnay
|
||||
|
||||
include std/datetime.e
|
||||
|
||||
datetime dt
|
||||
|
||||
dt = new(2009, 3, 7, 19, 30)
|
||||
dt = add(dt, 12, HOURS)
|
||||
printf(1, "%s EST\n", {format(dt, "%B %d %Y %I:%M %p")})
|
||||
34
Task/Date-manipulation/Pluto/date-manipulation.pluto
Normal file
34
Task/Date-manipulation/Pluto/date-manipulation.pluto
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
local function format_date(y, mo, d, h, mi, tz)
|
||||
local f = "%B %d %Y %I:%M%p " .. tz
|
||||
local tm = os.time({year = y, month = mo, day = d, hour = h, min = mi})
|
||||
return os.date(f, tm):replace(" 0", " "):replace("AM", "am"):replace("PM", "pm")
|
||||
end
|
||||
|
||||
local months = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
}
|
||||
|
||||
local date = "March 7 2009 7:30pm EST"
|
||||
print($"Original date/time : {date}")
|
||||
|
||||
local fields = date:split(" ")
|
||||
local fields2 = fields[4]:split(":")
|
||||
|
||||
local mo = months:findindex(|m| -> fields[1] == m , 1, true)
|
||||
local d = tonumber(fields[2])
|
||||
local y = tonumber(fields[3])
|
||||
local h = tonumber(fields2[1])
|
||||
local mi = tonumber(fields2[2]:sub(1, 2))
|
||||
local ap = fields2[2]:sub(3, 4)
|
||||
local tz = fields[5]
|
||||
if ap == "pm" then h += 12 end
|
||||
if h == 12 or h == 24 then h -= 12 end
|
||||
|
||||
-- Time and date 12 hours later
|
||||
local date2 = format_date(y, mo, d, h + 12, mi, tz)
|
||||
print($"12 hours later : {date2}")
|
||||
|
||||
-- Switch to MST time zone which is 2 hours earlier than EST.
|
||||
local date3 = format_date(y, mo, d, h + 10, mi, "MST")
|
||||
print($"Adjusted to MST : {date3}")
|
||||
4
Task/Date-manipulation/PowerShell/date-manipulation.ps1
Normal file
4
Task/Date-manipulation/PowerShell/date-manipulation.ps1
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")
|
||||
24
Task/Date-manipulation/Rebol/date-manipulation-1.rebol
Normal file
24
Task/Date-manipulation/Rebol/date-manipulation-1.rebol
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Rebol [
|
||||
Title: "Date Manipulation"
|
||||
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"
|
||||
43
Task/Date-manipulation/Rebol/date-manipulation-2.rebol
Normal file
43
Task/Date-manipulation/Rebol/date-manipulation-2.rebol
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
put system/catalog 'time-zones make map! [
|
||||
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
|
||||
]
|
||||
to-date: function/with [
|
||||
"Converts to date! value."
|
||||
value [any-type!] "May be also a standard Internet date string/binary"
|
||||
/utc "Returns the date with UTC zone"
|
||||
][
|
||||
if all [
|
||||
any [string? value binary? value]
|
||||
parse value [
|
||||
5 skip
|
||||
copy day: 1 2 numeric sp
|
||||
copy month: 3 alpha sp
|
||||
copy year: 1 4 numeric sp
|
||||
copy time: to sp sp
|
||||
[copy zone: [plus-minus 4 numeric] | no-case "GMT" (zone: "+0")]
|
||||
to end ; ignore the rest (like comments in mime fields)!
|
||||
|
|
||||
copy day: 1 2 numeric #"-"
|
||||
copy month: 1 2 numeric #"-"
|
||||
copy year: 1 4 numeric sp
|
||||
copy time: [1 2 numeric #":" 1 2 numeric opt [#":" 1 2 numeric]]
|
||||
to end
|
||||
|
|
||||
copy month: some alpha sp
|
||||
copy day: 1 2 numeric sp
|
||||
copy year: 1 4 numeric sp
|
||||
copy time: [1 2 numeric #":" 1 2 numeric opt [#":" 1 2 numeric]]
|
||||
opt ["pm" (time: 12:00 + to time! time) | "am"] sp
|
||||
copy zone: 3 4 alpha (zone: select system/catalog/time-zones to word! zone)
|
||||
]
|
||||
][
|
||||
value: to string! rejoin [day "-" month "-" year "/" time any [zone ""]]
|
||||
]
|
||||
if all [value: to date! value utc] [ value/timezone: 0 ]
|
||||
value
|
||||
] system/catalog/bitsets
|
||||
|
||||
probe 12:00 + to-date "March 7 2009 7:30pm EST"
|
||||
probe 12:00 + to-date "Sat, 7 Mar 2009 19:30:00 -0500"
|
||||
4
Task/Date-manipulation/Rye/date-manipulation.rye
Normal file
4
Task/Date-manipulation/Rye/date-manipulation.rye
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
t: datetime "2009-03-07T07:30:00"
|
||||
; returns [Time: 2009-03-07 07:30:00]
|
||||
t + 12 .hours
|
||||
; returns [Time: 2009-03-07 19:30:00]
|
||||
Loading…
Add table
Add a link
Reference in a new issue