Allow int input when using a formatstring in into datetime#13541
Allow int input when using a formatstring in into datetime#13541fdncred merged 2 commits intonushell:mainfrom
int input when using a formatstring in into datetime#13541Conversation
|
seems reasonable to me |
|
Thanks! Should be ready now with a test case in place. |
|
Thinking a bit more about this I'm wondering if this is right. Should we be converting an int to a string? You can clearly do |
Sure, the user can multiply the Unix epoch by 1_000_000_000 as well, but > let times = [
1722821463
1722821584
1722821588
]
# Option 1 - Unwieldy because of the multiplication/conversion
> $times | each { $in * 1_000_000_000 | into datetime }
# Option 2 - Works, just slightly more verbose
> $times | each { to text | into datetime -f '%s' }
# Option 3 (this PR)
> $times | each { into datetime -f '%s' }In the last two cases, either way, it gets converted to a string. Either internally with this PR or manually by the user with
Yup - Exactly. But if you want to specify a format string to do seconds (Unix epoch) instead of nanoseconds (without this PR) you get a (to me) unexpected refusal.
Well, I don't have to convert to string internally. I could write a new match arm using The conversion here is just a DRY tool. |
I don't understand what you mean here. I've fine with your other answers but was confused by the above statement. |
Yeah, apologies - I misread your example at first - I've edited the above based on what you actually said. |
But using nanoseconds. To use an epoch, the int still requires some form of conversion. |
|
thanks |
Description
When using a format string,
into datetimewould disallow aninteven when it logically made sense. This was mainly a problem when attempting to convert a Unix epoch to Nushelldatetime. Unix epochs are often stored or returned asintin external data sources.While the solution was simply to
| to texttheint, this PR handles the use-case automatically.Essentially a ~5 line change that just moves the current parsing to a closure that is called for both Strings and Ints-converted-to-Strings.
User-Facing Changes
After the change:
Tests + Formatting
Test case added.
toolkit fmttoolkit clippytoolkit testtoolkit test stdlibAfter Submitting