Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,97 +0,0 @@
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;

View file

@ -1,121 +0,0 @@
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.

View file

@ -1,40 +0,0 @@
(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)))

View file

@ -1,41 +0,0 @@
(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)))

View file

@ -1,10 +0,0 @@
--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")})

View file

@ -1,12 +1,7 @@
-->
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins<span style="color: #0000FF;">\<span style="color: #004080;">timedate<span style="color: #0000FF;">.<span style="color: #000000;">e</span>
<span style="color: #7060A8;">set_timedate_formats<span style="color: #0000FF;">(<span style="color: #0000FF;">{<span style="color: #008000;">"Mmmm d yyyy h:mmpm tz"<span style="color: #0000FF;">}<span style="color: #0000FF;">)</span>
<span style="color: #004080;">timedate</span> <span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string<span style="color: #0000FF;">(<span style="color: #008000;">"March 7 2009 7:30pm EST"<span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">twelvehours</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta<span style="color: #0000FF;">(<span style="color: #000000;">hours<span style="color: #0000FF;">:=<span style="color: #000000;">12<span style="color: #0000FF;">)</span>
<span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">adjust_timedate<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">,<span style="color: #000000;">twelvehours<span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?<span style="color: #7060A8;">format_timedate<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">)</span>
<span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">change_timezone<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">,<span style="color: #008000;">"ACDT"<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- extra credit</span>
<span style="color: #0000FF;">?<span style="color: #7060A8;">format_timedate<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">)</span>
<span style="color: #000000;">td</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">adjust_timedate<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">,<span style="color: #7060A8;">timedelta<span style="color: #0000FF;">(<span style="color: #000000;">days<span style="color: #0000FF;">:=<span style="color: #000000;">31<span style="color: #0000FF;">*<span style="color: #000000;">4<span style="color: #0000FF;">)<span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?<span style="color: #7060A8;">format_timedate<span style="color: #0000FF;">(<span style="color: #000000;">td<span style="color: #0000FF;">)
<!--
include builtins\timedate.e
set_timedate_formats({"Mmmm d yyyy h:mmpm tz"})
timedate td = parse_date_string("March 7 2009 7:30pm EST")
td = adjust_timedate(td,timedelta(hours:=12)) ?format_timedate(td)
-- extra credit, plus daylight savings
td = change_timezone(td,"ACDT") ?format_timedate(td)
td = adjust_timedate(td,timedelta(days:=31*4)) ?format_timedate(td)

View file

@ -1,4 +0,0 @@
$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

@ -1,24 +0,0 @@
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"