-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc9429d
commit 913880c
Showing
2 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |