I'll definitely be using this but I'd suggest replacing print with println.
It's supposed to be usable "inline", so it shouldn't print a newline. (E.g. `touch note-$(tu yesterday).md`)
Some terminals have an option to still write the $ prompt to the next line and use an enter symbol (⏎) to signify that no newline was printed.
> The shell shall expand the command substitution by executing command in a subshell environment (see Shell Execution Environment) and replacing the command substitution (the text of command plus the enclosing "$()" or backquotes) with the standard output of the command, removing sequences of one or more <newline> characters at the end of the substitution. Embedded <newline> characters before the end of the output shall not be removed; however, they may be treated as field delimiters and eliminated during field splitting, depending on the value of IFS and quoting that is in effect. If the output contains any null bytes, the behavior is unspecified.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...
I don't know of any shell that doesn't follow that.
It's not command substitution but the contentes in $variables will be expanded and splitted so you need to quote them or the newlines will get lost.
$ touch asdd
$ foo=$(echo -e '\n\nboop\n*dd\n'); echo $foo "$foo"
boop asdd
boop
*dd
Try create files with new lines and globbing in them, and forget to use quotes around filenames. Chaos ensues.That display-format appears to be (derived from?) ISO 8601. And I think ISO 8601 is not bound to UTC; it could equally be used to represent Solar Time. Possibly the most natural representation of a UTC instant would be an integer, because fundamentally UTC is a count of milliseconds.
Just quibbling about terminology! Not knocking the program, I like it.
It's not! It's a subtle point, but because of leap seconds, the correct representation of UTC is the tuple (year, month, day, hour, minute, second, ...), with the `...` being filled in with your desired precision.
From: http://www.madore.org/~david/computers/unix-leap-seconds.htm...
> Unlike TAI and UT1, the UTC time scale should not be considered as a pure real number (or seconds count): instead, it should be viewed as a broken-down time (year-month-day-hour-minute-second-fraction) in which the number of seconds ranges from 0 to 60 inclusive (there can be 61 or 59 seconds in a minute); during a positive leap second the number of seconds takes the value 60 (while a negative leap second would skip the value 59, but this has never occurred).
...
> If we attempt to condense UTC to a single number (say, the number of seconds since 1970-01-01T00:00:00 or since 1900-01-01T00:00:00, or the number of 86400s-days since 1858-11-17T00:00:00, or something of the sort), we encounter the problem that the same value can refer to two different instants since the clock has been set back one second (negative leap seconds, of course, would cause no such difficulty).
Most datetime libraries get this wrong. I know because I'm working on a new one that specifically doesn't get this wrong.
I was not aware GNU date could do this as well, but that also doesn't parse my original example.
A small configuration of adding your preferred timezone or reading the system timezone would be nice. The code seems simple enough that I may try to add it myself.
I'd be very happy about a PR! ;-)
I was trying to do stuff with chrono-english [0] and parse_datetime [1].
I noticed chrono-english doesn't work for both `tomorrow 4pm` and `4pm tomorrow`.
I second the desire for the timezone support.
[0] https://docs.rs/chrono-english/ [1] https://docs.rs/parse_datetime/
tu today -> 2024-03-16T12:56:41.905455Z
tu tomorrow -> 2024-03-17T12:56:41.905455Z
I interpret "today" as the time period between 00:00 and 23:59:59.999999, and tomorrow similarly.And then you end up with needing a locale based week, since different cultures (e.g. US versus UK) use different days to start the week (Sunday/Monday)
this is never ambiguous. "saturday" is the saturday of the current week, and "next saturday" is the saturday of the following week
What is that based on? Your personal perception is not evidence of wider ambiguity either way (and neither is mine).
I run my servers in UTC (as everyone should (and some (many?) products require)))
Everything else handles timezones "correctly" (in my experience)
For production stuff like servers I wouldn't even think about it.
But I guess it solved the author's problem and we can't argue with that.
Abstracting it even further into NLP is even scarier.
I don't have a solution I just feel deep pain about this as a remote worker dealing with logs and timestamps and who is where, there has to be some different way.
Basically, how humans measure time is psychopathic.
GNU date almost does the same as their examples:
date -Is -ud 'today' --> 2024-04-12T14:04:08+00:00
date -Is -ud 'tomorrow' --> 2024-04-13T14:04:08+00:00
date -Is -ud '2 day' --> 2024-04-14T14:04:08+00:00
date -Is -ud '9 week' --> 2024-06-14T14:04:08+00:00
date -Is -ud '1 month' --> 2024-05-12T14:04:08+00:00
date -Is -ud '2024-04-10T13:31:46+04:00' --> 2024-04-10T09:31:46+00:00
date -Is -ud 'Wed, 14 Feb 2024 23:16:09 GMT' --> 2024-02-14T23:16:09+00:00
And if you want Z format, you can use a custom format string: date -ud '1 month' +'%FT%TTZ' --> 2024-05-12T14:13:22TZ
So it would be easy enough to add an alias/function to your shell configurations and just use built-in date rather than installing a new program. Assuming GNU date relative date parsing meets your needs - I don't think it's quite as flexible as some libraries, e.g. in Python.The safest format for a stored future timestamp is a local time, an IANA timezone name, and, if you need it for efficiency, a derived UTC time. But you need to rederive the UTC time whenever the timezone database changes (or whenever the related entity/user changes their timezone), or it may become incorrect, as above.
Then, if a state decides to stop doing DST, or any other funkiness like that, you can still get the time right.
I should note that it is not possible to make a database of geolocation->UTC offset that is legal in all countries, since there are countries with disputed borders, some of which care very much that no software imply the "wrong" border.
> If you're worried about the future timestamp being at a specific local time (say 10 AM on a future date), it's actually better to store a naive time and a location than the IANA timezone name.
Europe/Oslo would be the IANA name for mainland Norway (Svalbard and Jan Mayen are in different IANA regions).
If you're meeting somewhere at a specific time, you might as well specify that place really precisely (Maybe: Nidaros Cathedral, Trondheim, Norway) and then use that place to infer the proper UTC offset when the date approaches.
There's no perfect solution as landmarks, names, &c. can all change.
Sorry yeah, this is the one I was thinking of when I said Oslo/Norway.
Agree with your other points as well.
I guess to increase the long term robustness one could record some additional data:
GPS coordinates for the intended event
GNSS coordinates using another system such as BDS or GLONASS for the intended event
The current time with time zone at the time when the record was created
The IANA name of the location where the record was created