Skip to content

Commit

Permalink
Convert date scripts to nushell
Browse files Browse the repository at this point in the history
  • Loading branch information
NonlinearFruit committed Jan 6, 2024
1 parent bc9429d commit 913880c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
33 changes: 21 additions & 12 deletions scripts/datediff
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
d1=$(date -d now +%s)
d2=$(date -d "$*" +%s)
delta=$((d1 - d2))
# echo $(( delta )) seconds
# echo $(( delta / 60 )) minutes
# echo $(( delta / (60*60) )) hours
# echo $(( delta / (60*60*24) )) days
# echo $(( delta / (60*60*24*7) )) weeks
# echo $(( delta / (60*60*24*30) )) months
# echo $(( delta / (60*60*24*365) )) years
# echo $(( delta / (60*60*24*365*10) )) decades
echo $(( delta / (60*60*24) ))
#!/usr/bin/env nu

def main [
date: string # Date to harken back to
--seconds # Diff in seconds
--minutes # Diff in minutes
--hours # Diff in hours
--days = true # Diff in days
--weeks # Diff in weeks
--years # Diff in years
] {
let then = $date | into datetime
let denominator = match [$seconds $minutes $hours $days $weeks] {
[true _ _ _ _] => 1sec,
[_ true _ _ _] => 1min,
[_ _ true _ _] => 1hr,
[_ _ _ true _] => 1day,
[_ _ _ _ true] => 1wk,
}
((date now) - $then) / $denominator | math round --precision 3
}
19 changes: 16 additions & 3 deletions scripts/sundays
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
birthday=$*
daysTill18=$(datediff $birthday +18 years)
echo "-1 * ${daysTill18} / 7" | bc
#!/usr/bin/env nu

def main [
birthdate: string # Someone's birthday
] {
$birthdate
| date to-record
| update year {$in + 18}
| $"($in.month)-($in.day)-($in.year)"
| into datetime
| datediff $in --weeks
| into float
| $in / 7
| math abs
| math floor
}

0 comments on commit 913880c

Please sign in to comment.