Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,44 @@
with Ada.Text_IO;
procedure Convert is
type Time is range 0 .. 10_000*356*20*60*60; -- at most 10_000 years
subtype Valid_Duration is Time range 1 .. 10_000*356*20*60*60;
type Units is (WK, D, HR, MIN, SEC);
package IO renames Ada.Text_IO;
Divide_By: constant array(Units) of Time := (1_000*53, 7, 24, 60, 60);
Split: array(Units) of Time;
No_Comma: Units;
X: Time;
Test_Cases: array(Positive range <>) of Valid_Duration :=
(6, 60, 3659, 7_259, 86_400, 6_000_000, 6_001_200, 6_001_230, 600_000_000);
begin
for Test_Case of Test_Cases loop
IO.Put(Time'Image(Test_Case) & " SECONDS =");
X := Test_Case;
-- split X up into weeks, days, ..., seconds
No_Comma := Units'First;
for Unit in reverse Units loop -- Unit = SEC, ..., WK (in that order)
Split(Unit) := X mod Divide_By(Unit);
X := X / Divide_By(Unit);
if Unit > No_Comma and Split(Unit)>0 then
No_Comma := Unit;
end if;
end loop;
-- ouput weeks, days, ..., seconds
for Unit in Units loop -- Unit = WK, .., SEC (in that order)
if Split(Unit) > 0 then
IO.Put(Time'Image(Split(Unit)) & " " & Units'Image(Unit) &
(if No_Comma > Unit then "," else ""));
end if;
end loop;
IO.New_Line;
end loop;
end Convert;

View file

@ -0,0 +1,74 @@
identification division.
program-id. fmt-dura.
data division.
working-storage section.
1 input-seconds pic 9(8).
1 formatted-duration pic x(30) global.
1 fractions.
2 weeks pic z(3)9.
2 days pic z(3)9.
2 hours pic z(3)9.
2 minutes pic z(3)9.
2 seconds pic z(3)9.
1 .
2 weeks-str pic x(4) value "wk".
2 days-str pic x(4) value "d".
2 hours-str pic x(4) value "hr".
2 minutes-str pic x(4) value "min".
2 seconds-str pic x(4) value "sec".
1 work binary global.
2 str-pos pic 9(4).
2 chars-transferred pic 9(4).
procedure division.
begin.
display "Enter duration (seconds): " no advancing
accept input-seconds
divide input-seconds by 60 giving input-seconds
remainder seconds
divide input-seconds by 60 giving input-seconds
remainder minutes
divide input-seconds by 24 giving input-seconds
remainder hours
divide input-seconds by 7 giving weeks
remainder days
move 1 to str-pos
call "fmt" using weeks weeks-str
call "fmt" using days days-str
call "fmt" using hours hours-str
call "fmt" using minutes minutes-str
call "fmt" using seconds seconds-str
display formatted-duration
stop run
.
identification division.
program-id. fmt.
data division.
working-storage section.
77 nothing pic x.
linkage section.
1 formatted-value pic x(4).
1 duration-size pic x(4).
procedure division using formatted-value duration-size.
begin.
if function numval (formatted-value) not = 0
perform insert-comma-space
unstring formatted-value delimited all space
into nothing formatted-duration (str-pos:)
count chars-transferred
add chars-transferred to str-pos
string space delimited size
duration-size delimited space
into formatted-duration pointer str-pos
end-if
exit program
.
insert-comma-space.
if str-pos > 1
move ", " to formatted-duration (str-pos:)
add 2 to str-pos
end-if
.
end program fmt.
end program fmt-dura.

View file

@ -0,0 +1,24 @@
function divide(integer n, integer d)
return {floor(n/d), remainder(n,d)}
end function
procedure format_time(atom secs)
integer sec, min, hour, day, week
{min, sec} = divide(secs, 60)
{hour, min} = divide(min, 60)
{day, hour} = divide(hour, 24)
{week, day} = divide(day, 7)
sequence fmt = ""
sequence s = {}
if week then fmt &= "%d wk" s &= {week} end if
if day then fmt &= ", %d d" s &= {day} end if
if hour then fmt &= ", %d hr" s &= {hour} end if
if min then fmt &= ", %d min" s &= {min} end if
if sec then fmt &= ", %d sec" s &= {sec} end if
if fmt[1] = ',' then fmt = remove(fmt, 1, 2) end if
printf(1, fmt & "\n", s)
end procedure
format_time(7259)
format_time(86400)
format_time(6000000)

View file

@ -1,6 +1,4 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">7259</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">86400</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000000</span><span style="color: #0000FF;">)</span>
<!--
with javascript_semantics
?elapsed(7259)
?elapsed(86400)
?elapsed(6000000)

View file

@ -1,5 +1,3 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #000000;">6000000</span><span style="color: #0000FF;">-</span><span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">10</span><span style="color: #0000FF;">))</span>
<!--
with javascript_semantics
include timedate.e
?elapsed(6000000-timedelta(days:=6,hours:=10))

View file

@ -0,0 +1,19 @@
local function duration(s)
if s < 1 then return "0 sec" end
local dur = ""
local divs = {7, 24, 60, 60, 1}
local units = {"wk", "d", "hr", "min", "sec"}
local t = divs:reduce(|prod, div| -> prod * div, 1)
for i = 1, #divs do
local u = s // t
if u > 0 then
dur ..= $"{u} {units[i]}, "
s %= t
end
t //= divs[i]
end
if dur:endswith(", ") then dur = dur:sub(1, -3) end
return dur
end
for {7259, 86400, 6000000} as s do print(duration(s)) end

View file

@ -0,0 +1,116 @@
function Get-Time
{
<#
.SYNOPSIS
Gets a time string in the form: # wk, # d, # hr, # min, # sec
.DESCRIPTION
Gets a time string in the form: # wk, # d, # hr, # min, # sec
(Values of 0 are not displayed in the string.)
Days, Hours, Minutes or Seconds in any combination may be used
as well as Start and End dates.
When used with the -AsObject switch an object containing properties
similar to a System.TimeSpan object is returned.
.INPUTS
DateTime or Int32
.OUTPUTS
String or PSCustomObject
.EXAMPLE
Get-Time -Seconds 7259
.EXAMPLE
Get-Time -Days 31 -Hours 4 -Minutes 8 -Seconds 16
.EXAMPLE
Get-Time -Days 31 -Hours 4 -Minutes 8 -Seconds 16 -AsObject
.EXAMPLE
Get-Time -Start 3/10/2016 -End 1/20/2017
.EXAMPLE
Get-Time -Start (Get-Date) -End (Get-Date).AddSeconds(6000000)
#>
[CmdletBinding(DefaultParameterSetName='Date')]
Param
(
# Start date
[Parameter(Mandatory=$false, ParameterSetName='Date',
Position=0)]
[datetime]
$Start = (Get-Date),
# End date
[Parameter(Mandatory=$false, ParameterSetName='Date',
Position=1)]
[datetime]
$End = (Get-Date),
# Days in the time span
[Parameter(Mandatory=$false, ParameterSetName='Time')]
[int]
$Days = 0,
# Hours in the time span
[Parameter(Mandatory=$false, ParameterSetName='Time')]
[int]
$Hours = 0,
# Minutes in the time span
[Parameter(Mandatory=$false, ParameterSetName='Time')]
[int]
$Minutes = 0,
# Seconds in the time span
[Parameter(Mandatory=$false, ParameterSetName='Time')]
[int]
$Seconds = 0,
[switch]
$AsObject
)
Begin
{
[PSCustomObject]$timeObject = "PSCustomObject" |
Select-Object -Property Weeks,RemainingDays,
Days,Hours,Minutes,Seconds,Milliseconds,Ticks,
TotalDays,TotalHours,TotalMinutes,TotalSeconds,TotalMilliseconds
[int]$remainingDays = 0
[int]$weeks = 0
[string[]]$timeString = @()
}
Process
{
switch ($PSCmdlet.ParameterSetName)
{
'Date' { $timeSpan = New-TimeSpan -Start $Start -End $End }
'Time' { $timeSpan = New-TimeSpan -Days $Days -Hours $Hours -Minutes $Minutes -Seconds $Seconds }
}
$weeks = [System.Math]::DivRem($timeSpan.Days, 7, [ref]$remainingDays)
$timeObject.Weeks = $weeks
$timeObject.RemainingDays = $remainingDays
$timeObject.Days = $timeSpan.Days
$timeObject.Hours = $timeSpan.Hours
$timeObject.Minutes = $timeSpan.Minutes
$timeObject.Seconds = $timeSpan.Seconds
$timeObject.Milliseconds = $timeSpan.Milliseconds
$timeObject.Ticks = $timeSpan.Ticks
$timeObject.TotalDays = $timeSpan.TotalDays
$timeObject.TotalHours = $timeSpan.TotalHours
$timeObject.TotalMinutes = $timeSpan.TotalMinutes
$timeObject.TotalSeconds = $timeSpan.TotalSeconds
$timeObject.TotalMilliseconds = $timeSpan.TotalMilliseconds
}
End
{
if ($AsObject) { return $timeObject }
if ($timeObject.Weeks) { $timeString += "$($timeObject.Weeks) wk" }
if ($timeObject.RemainingDays) { $timeString += "$($timeObject.RemainingDays) d" }
if ($timeObject.Hours) { $timeString += "$($timeObject.Hours) hr" }
if ($timeObject.Minutes) { $timeString += "$($timeObject.Minutes) min" }
if ($timeObject.Seconds) { $timeString += "$($timeObject.Seconds) sec" }
return ($timeString -join ", ")
}
}

View file

@ -0,0 +1,15 @@
duration <- function(t){
max_units <- c("sec"=60, "min"=60, "hr"=24, "d"=7)
times <- numeric(4)
for(i in 1:4){
times[i] <- t%%max_units[i]
t <- t%/%max_units[i]
}
times <- c(times, t)
names(times) <- c(names(max_units), "wk")
times <- rev(Filter(`+`, times))
cat(paste(times, names(times)), sep=", ")
cat("\n")
}
lapply(c(7259, 86400, 6000000), duration) |> invisible()

View file

@ -0,0 +1,43 @@
const durations = [0, 7, 84, 7259, 86400, 6_000_000]
struct DurationCalculator {
mut:
weeks int
days int
hours int
minutes int
seconds int
}
fn compound_duration(n int) string {
if n < 0 { return "" }
if n == 0 { return "0 sec" }
mut calculator := DurationCalculator{}
mut divisor := 7 * 24 * 60 * 60
mut rem := n
mut result := ""
calculator.weeks = n / divisor
rem = n % divisor
divisor /= 7
calculator.days = rem / divisor
rem %= divisor
divisor /= 24
calculator.hours = rem / divisor
rem %= divisor
divisor /= 60
calculator.minutes = rem / divisor
calculator.seconds = rem % divisor
if calculator.weeks > 0 { result += "${calculator.weeks} wk, " }
if calculator.days > 0 { result += "${calculator.days} d, " }
if calculator.hours > 0 { result += "${calculator.hours} hr, " }
if calculator.minutes > 0 { result += "${calculator.minutes} min, " }
if calculator.seconds > 0 { result += "${calculator.seconds} sec" }
else { result = result.substr(0, result.len - 2) }
return result
}
fn main() {
for duration in durations {
println("${duration}\t-> ${compound_duration(duration)}")
}
}

View file

@ -0,0 +1,37 @@
Function compound_duration(n)
Do Until n = 0
If n >= 604800 Then
wk = Int(n/604800)
n = n-(604800*wk)
compound_duration = compound_duration & wk & " wk"
End If
If n >= 86400 Then
d = Int(n/86400)
n = n-(86400*d)
If wk > 0 Then compound_duration = compound_duration & ", " End If
compound_duration = compound_duration & d & " d"
End If
If n >= 3600 Then
hr = Int(n/3600)
n = n-(3600*hr)
If d > 0 Then compound_duration = compound_duration & ", " End If
compound_duration = compound_duration & hr & " hr"
End If
If n >= 60 Then
min = Int(n/60)
n = n-(60*min)
If hr > 0 Then compound_duration = compound_duration & ", " End If
compound_duration = compound_duration & min & " min"
End If
If n > 0 Then
If min > 0 Then compound_duration = compound_duration & ", " End If
compound_duration = compound_duration & ", " & n & " sec"
n = 0
End If
Loop
End Function
'validating the function
WScript.StdOut.WriteLine compound_duration(7259)
WScript.StdOut.WriteLine compound_duration(86400)
WScript.StdOut.WriteLine compound_duration(6000000)