Skip to content

into datetime: accept duration as input - #19402

Merged
fdncred merged 2 commits into
nushell:mainfrom
dead10ck:feat/into-datetime/duration
Nov 12, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
dead10ck:feat/into-datetime/duration

Conversation

@dead10ck

@dead10ck dead10ck commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

Durations can now be given as input to into datetime; they are interpreted as Unix seconds. This makes it easier to convert ints into datetimes when they represent Unix timestamps in units other than seconds, e.g.

❯ 1614434140123 | into duration --unit ms | into datetime
Sat, 27 Feb 2021 13:55:40 +0000 (5 years ago)

User-facing changes (Release notes)

Durations can now be given as input to into datetime; they are interpreted as Unix seconds. This makes it easier to convert ints into datetimes when they represent Unix timestamps in units other than seconds, e.g.

❯ 1614434140123 | into duration --unit ms | into datetime
Sat, 27 Feb 2021 13:55:40 +0000 (5 years ago)

Additional notes

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟢 A few small things

Durations work as input on the default path, with --offset, --timezone and cell paths, and at both ends of the duration range. What's left is small: two error messages, a list signature, a few tests and the release note.

Findings: 0 High severity · 0 Medium severity · 5 Low severity

Open (5)

Notes from my clanker, checked on 39c3916. Built the branch and ran each case on the branch binary and on 0.116.2 (c302d6f). CI already ran fmt, clippy and the tests on Linux, macOS and Windows for this head, so I didn't rerun them.

@NotTheDr01ds

NotTheDr01ds commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What's the advantage of this over:

1614434140123 * 1000000 | into datetime
# => Sat, 27 Feb 2021 13:55:40 +0000 (5 years ago)

or for duration based modifications to the Unix epoch:

(0 | into datetime) + 1wk
# => Thu, 8 Jan 1970 00:00:00 +0000 (56 years ago)

@dead10ck
dead10ck force-pushed the feat/into-datetime/duration branch from 39c3916 to cff9385 Compare November 7, 2026 18:31
@dead10ck

dead10ck commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Ok I think I got all the review comments. For testing, I've added to the unit tests within the same file, rather than the integration tests.

@dead10ck

dead10ck commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

What's the advantage of this over:

1614434140123 * 1000000 | into datetime
# => Sat, 27 Feb 2021 13:55:40 +0000 (5 years ago)

or for duration based modifications to the Unix epoch:

(0 | into datetime) + 1wk
# => Thu, 8 Jan 1970 00:00:00 +0000 (56 years ago)

Sorry, is this a serious question you want answered .... ? Working with rich types is clearer and less error-prone than working with raw numbers. No thinking about how many zeros to convert the timestamp into nanoseconds, or even having to know or care that the internal representation of a datetime or a duration is a nanosecond. One may as well ask what the advantage is of having a distinct duration type at all, when one could just convert to and from ints.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟢 A few small things

3 of the 5 threads are fixed and resolved: the --format error, the fallback error text and the list<duration> signature. Two are left. The new offset tests can't see a dropped offset and a few cases still have no test, and the release notes section is still empty.

Findings: 0 High severity · 0 Medium severity · 2 Low severity

Open (2)

Notes from my clanker, checked on 7c5045b. Built the branch and ran probe.sh and recheck.sh on it and on main (4492226). Ran the datetime unit tests with the Zone::East and Zone::Local arms changed to return UTC (20 passed), then restored the file. CI is green on this head (11 checks), so I didn't rerun the full test suite, clippy or fmt locally.

@fdncred

fdncred commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

please respond to each review comment so we can make sure nothing is missed

@dead10ck

dead10ck commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

please respond to each review comment so we can make sure nothing is missed

Ok sure, I just replied to the two still open. When the review comments are clearly AI-generated, it's not very clear what you, as the human, actually want, and what is just AI noise.

@fdncred

fdncred commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Ok sure, I just replied to the two still open. When the review comments are clearly AI-generated, it's not very clear what you, as the human, actually want, and what is just AI noise.

ya, this one was a mess. sorry about that. i'm kind of the lone ranger here sometimes. it's a lot to keep up with.

@fdncred

fdncred commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

These are the remaining things we need looked at.

  1. update user facing changes like i said above in spite of what the template says
  2. 🟢Low Four cases from the first comment still have no test

These four still have no test. Please add these to tests somewhere.

-1day | into datetime | to nuon                          # 1969-12-31T00:00:00+00:00
1sec | into datetime --offset -5 | to nuon               # 1969-12-31T19:00:01-05:00
1sec | into datetime --timezone Europe/Berlin | to nuon  # 1970-01-01T01:00:01+01:00
{a: 1sec} | into datetime a | to nuon                    # {a: 1970-01-01T00:00:01+00:00}

The first three fit as action unit tests next to yours (Zone::West(5), Zone::Tz(chrono_tz::Europe::Berlin)). The cell path goes through operate, which action tests can't reach, so that one needs a test in crates/nu-command/tests/commands/into_datetime.rs.

  1. 🟢Low This test passes without the offset

If the Zone::East arm in action ignores the offset and returns UTC, this test still passes. I tried it.

assert_eq! on two Value::dates compares the instant, not the offset. Same in nu: (1hr | into datetime --offset 8) == (1hr | into datetime) is true.

I'm not asking to change Value equality. Comparing instants is on purpose. One more line here checks the offset itself:

assert_eq!(actual.as_date().unwrap().offset().local_minus_utc(), 8 * 3600);

@dead10ck
dead10ck force-pushed the feat/into-datetime/duration branch 3 times, most recently from 68e08bf to 6e1e062 Compare November 11, 2026 21:26
@dead10ck

Copy link
Copy Markdown
Contributor Author

Ok, I think I got everything remaining.

Durations can be interpreted the same way as plain ints, i.e., as a
unix timestamp.
@dead10ck
dead10ck force-pushed the feat/into-datetime/duration branch from 6e1e062 to 287beea Compare November 11, 2026 21:29
@fdncred
fdncred merged commit f427d5e into nushell:main Nov 12, 2026
12 checks passed
@fdncred

fdncred commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 12, 2026
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section and removed status:wait-until-after-nushell-release labels Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants