Skip to content

Use native toml datetime type in to toml - #13018

Merged
fdncred merged 1 commit into
nushell:mainfrom
kaathewisegit:to-toml
Jun 7, 2024
Merged

fdncred merged 1 commit into
nushell:mainfrom
kaathewisegit:to-toml

Conversation

@kaathewisegit

@kaathewisegit kaathewisegit commented May 31, 2024 •

Copy link
Copy Markdown
Contributor

Description

Makes to toml use the toml::value::Datetime type, so that to toml serializes dates properly.

User-Facing Changes

to toml will now encode dates differently, in a native format instead of a string. This could, in theory, break some workflows:

# Before:
~> {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
Fri, 31 May 2024 00:00:00 +0000 (10 hours ago)
# After:
~> {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
Error: nu::shell::only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #13:1:36]
 1 │ {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
   ·                                    ────┬────                  ──────┬──────
   ·                                        │                            ╰── only string and int input data is supported
   ·                                        ╰── input type: date
   ╰────

Fix #11751

@fdncred

fdncred commented May 31, 2024 •

Copy link
Copy Markdown
Contributor

It looks like after the change in datetime format from toml is already converting the datetime text into a nushell datetime value since the datetime text is RFC 3339 formatted.

Also, it would be helpful to show what this format looks like.

❯ {datetime: 2024-05-31} | to toml
datetime = 2024-05-31T00:00:00+00:00

or

❯ {datetime: (date now)} | to toml
datetime = 2024-05-31T06:39:14.282464-05:00

Uses `toml::value::DateTime` instead of `toml::Value::String`.

Fix #11751
@NotTheDr01ds

NotTheDr01ds commented Jun 7, 2024 •

Copy link
Copy Markdown
Contributor

Adding some "breaking change for dummies" doc here since the original PR description wasn't clear to me (the dummy ;-)). I needed to fetch the PR to see what it was really doing.

User-Facing Changes

Nushell 0.91 previously changed from toml handle native TOML datetime values (which should not be quoted). However, to toml was not updated, meaning that round-tripping TOML (from toml | to toml) required an extra into datetime. This PR completes the corresponding to toml support for native TOML datetimes.

For code that is using into datetime, this will result in a breaking change that is easily resolved by simply removing the now-unnecessary into datetime:

# In 0.94.2
~> {datetime: 2024-05-31} | to toml
datetime = "2024-05-31T00:00:00+00:00"
# After this PR
~> {datetime: 2024-05-31} | to toml
datetime = 2024-05-31T00:00:00+00:00

# In 0.94.2
~> {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
Fri, 31 May 2024 00:00:00 +0000 (a week ago)
# After this PR
~> {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
Error: nu::shell::only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #16:1:36]
 1 │ {datetime: 2024-05-31} | to toml | from toml | get datetime | into datetime
   ·                                    ────┬────                  ──────┬──────
   ·                                        │                            ╰── only string and int input data is supported
   ·                                        ╰── input type: date
   ╰────

# Fix - remove `into datetime`
~> {datetime: 2024-05-31} | to toml | from toml | get datetime
Fri, 31 May 2024 00:00:00 +0000 (a week ago)

@fdncred fdncred added notes:breaking-changes Noted in Breaking Changes section deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way labels Jun 7, 2024
@fdncred
fdncred merged commit 2d0a60a into nushell:main Jun 7, 2024
@fdncred

fdncred commented Jun 7, 2024

Copy link
Copy Markdown
Contributor

let's see how much this breaks things. thanks

@hustcer hustcer added this to the v0.95.0 milestone Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way notes:breaking-changes Noted in Breaking Changes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to/from toml doesn't use native TOML date format

4 participants