Added lumen-assono-worktime-calc
This commit is contained in:
42
config.nu
42
config.nu
@@ -37,3 +37,45 @@ export def lumen-search-content [searchstr = string]: any -> table {
|
|||||||
}
|
}
|
||||||
} | compact content -e
|
} | compact content -e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export def lumen-assono-worktime-calc [datestr = string]: nothing -> any {
|
||||||
|
let $datestr = $datestr | str replace ' +' ' '
|
||||||
|
mut $dateArray = []
|
||||||
|
let $rawDateArray = $datestr | split row ' '
|
||||||
|
if (($rawDateArray | length) mod 2 == 1) {
|
||||||
|
mut $spliceCounter = true
|
||||||
|
for $i in $rawDateArray {
|
||||||
|
if ($spliceCounter) {
|
||||||
|
$dateArray = $dateArray | append $i
|
||||||
|
}
|
||||||
|
$spliceCounter = not $spliceCounter
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$dateArray = $rawDateArray
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($dateArray | length) mod 2 == 1) {
|
||||||
|
error make {msg: 'Uneven Times given!'}
|
||||||
|
}
|
||||||
|
|
||||||
|
mut $dateArrayOutput = []
|
||||||
|
mut $dateArrayOutputBuilderCounter = true
|
||||||
|
for $i in $dateArray {
|
||||||
|
$dateArrayOutput = $dateArrayOutput | append ($i | date from-human | format date '%H:%M')
|
||||||
|
if ($dateArrayOutputBuilderCounter) {
|
||||||
|
$dateArrayOutput = $dateArrayOutput | append '-'
|
||||||
|
} else {
|
||||||
|
$dateArrayOutput = $dateArrayOutput | append '|'
|
||||||
|
}
|
||||||
|
$dateArrayOutputBuilderCounter = not $dateArrayOutputBuilderCounter
|
||||||
|
}
|
||||||
|
let $dateArrayOutput = ($dateArrayOutput | drop 1) | str join ' '
|
||||||
|
|
||||||
|
# $dateArray[0]
|
||||||
|
mut $hours = 0min
|
||||||
|
while (($dateArray | length) > 0) {
|
||||||
|
$hours += ($dateArray | get 1 | into datetime) - ($dateArray | get 0 | into datetime)
|
||||||
|
$dateArray = $dateArray | skip 2
|
||||||
|
}
|
||||||
|
$"($dateArrayOutput)\n($hours | into string)"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user