Skip to content

Commit

Permalink
Merge pull request #1 from rhennigan/feature/just-testing
Browse files Browse the repository at this point in the history
Test pull request, please ignore
  • Loading branch information
rhennigan authored Oct 7, 2021
2 parents 2bc60b1 + 517553b commit db6cc6d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions RelativeTimeString/Definition.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
RelativeTimeString // ClearAll;

RelativeTimeString // Attributes = { Listable };

RelativeTimeString[ date1_? DateObjectQ, date2_? DateObjectQ ] :=
Module[ { diff, post, nice },
diff = date2 - date1;
post = If[ TrueQ @ Positive @ diff, " ago", " from now" ];
nice = Round @ ResourceFunction[ "SecondsToQuantity" ][ Abs @ diff ];
If[ QuantityMagnitude @ nice === 0,
"now",
StringJoin[
TextString[ nice /. r_Rational :> RuleCondition @ Round @ r ],
post
]
]
];

RelativeTimeString[ date_? DateObjectQ ] :=
RelativeTimeString[ date, DateObject[ Now, date[ "Granularity" ] ] ];

0 comments on commit db6cc6d

Please sign in to comment.