Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,44 +0,0 @@
|
|||
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;
|
||||
|
|
@ -4,7 +4,7 @@ Quantities: @[7 * 24 * 60 * 60, 24 * 60 * 60, 60 * 60, 60, 1]
|
|||
durationString: function [d][
|
||||
dur: d
|
||||
idx: 0
|
||||
result: new []
|
||||
result: []
|
||||
while [not? zero? dur][
|
||||
q: dur / Quantities\[idx]
|
||||
if not? zero? q [
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
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.
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
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 ", ")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
# Builds a string representation of a time period
|
||||
|
||||
Units ← {"second" "minute" "hour" "day" "week"}
|
||||
Units ← {"second" "minute" "hour" "day" "week"}
|
||||
Durations ← [60 60 24 7 9999]
|
||||
|
||||
Parts ← ⇌◌∧(⊙⊂⊃(⌊÷|◿))Durations⊙[] # seconds -> [S M H D W]
|
||||
Sunit ← /⍚$"_ _"⍥⍜(⊡1|⍚⊂⊙@s)≠□"1"⊢. # Stringify a unit
|
||||
String ← /◇$"_, _"⇌≡Sunit▽⊃(±|⍉⇌⊟Units°⋕) Parts
|
||||
≡(&p$"_s \t= _"⟜(□String))[7259 86400 6000000 14000000 31449599 31449601]
|
||||
Parts ← ⇌◌∧(⊙⊂⊃(⌊÷|◿))Durations⊙[] # seconds -> [S M H D W]
|
||||
Sunit ← /⍚$"_ _"⍥⍜(⊡1|⍚⊂⊙@s)≠□"1"⊢. # Stringify a unit, add plurals.
|
||||
String ← /◇$"_, _"⇌≡Sunit▽⊃(±|⍉⇌⊟Units°⋕) Parts # Build full string.
|
||||
≡(&p$"_s \t= _"⟜String)[7259 86400 6000000 14000000 31449599 31449601]
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue