casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
18.59k stars 421 forks source link

add datetime functions #1182

Open mbodmer opened 2 years ago

mbodmer commented 2 years ago

I propose the following functions:

References:

mbodmer commented 2 years ago

maybe related: #1020

casey commented 2 years ago

Thanks for the detailed writeup!

This sounds good to me. I'd be inclined to leave out timediff and timesince for now. In general, I try to avoid functions that don't naturally take and return strings, since that's the only type that just currently supports.

nk9 commented 2 years ago

If we're going to go to the trouble of providing functions to operate on datetimes, shouldn't we also make it possible to specify a datetime other than now? If these functions took an epoch timestamp, now() by default, they would be much more flexible. I don't think it will be that much more complex to actually implement this either, if we're already linking in strftime. Biggest complication would be parsing the epoch string into a float I think?

casey commented 2 years ago

We certainly could let them take a timestamp, although I'd wait to do that until someone has a specific use-case. That way we can ensure that it's both needed, and that what we implement works for the specific use-case.

So far I've avoided defining functions that take and return values that aren't strings, e.g., numbers.

runeimp commented 2 years ago

I'd just like to point out that colons in file/directory names can be very problematic, especially when considering multi-platform usage. You can quote or escape them much of the time for creation but many applications and some operating systems will barf hard attempting to manage a file or directory with a colon in its name.

Also the colon in the timezone offset is not recommended as well. Some ISO-8601 parsers don't like it for some reason. YMMV.

casey commented 3 weeks ago

I added datetime(format) and datetime_utc(format) in #2167. For now the format string must be specified, but it should be easy enough to add versions which have no arguments and which use a default format string.