Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description for #8205 and #8014 #821

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 64 additions & 5 deletions blog/2023-03-14-nushell_0_77.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ As part of this release, we also publish a set of optional plugins you can insta

# Themes of this release / New features

## More consistent timestamp handling
## More consistent timestamp handling

Simplified conversion between Nushell `date` type and unix timestamps ([#8244](https://github.com/nushell/nushell/pull/8244)).

Nushell now standardizes on representing a Unix timestamp as a number of *nanoseconds* relative to the unix epoch 1970-01-01 00:00:00 +0000 (UTC). Since the timestamp is stored in a (64 bit signed) Nushell `int` type, this limits the range of dates that can be represented to approximately 21-sep-1677 through 11-apr-2262.
Nushell now standardizes on representing a Unix timestamp as a number of *nanoseconds* relative to the unix epoch 1970-01-01 00:00:00 +0000 (UTC). Since the timestamp is stored in a (64 bit signed) Nushell `int` type, this limits the range of dates that can be represented to approximately 21-sep-1677 through 11-apr-2262.

In prior versions, Nushell attempted to extend the range of representable dates by allowing multiple resolutions of timestamps (seconds, milliseconds as well as nanoseconds) to be stored and relied on arbitrary range check heuristics to disambiguate the value intended. However, there were bugs in the checks and incorrect results could be produced.

Expand All @@ -42,12 +42,14 @@ Tue, 21 Sep 1677 00:12:43 +0000 (345 years ago)
```

The timestamp epoch is the standard unix epoch. Note the timezone is UTC/GMT:

```rust
〉0 | into datetime
Thu, 01 Jan 1970 00:00:00 +0000 (53 years ago)
```

`<datetime> | into int` can now produce an error if the input is outside the supported range:

```rust
〉1492-10-12 | into int
Error: nu::shell::incorrect_value
Expand All @@ -61,6 +63,7 @@ Error: nu::shell::incorrect_value
```

And finally, although not strictly required by the above fix, `<date> | date to-record` and `<date> | date to-table` now have a `nanosecond` field containing the subsecond residue of the input value (however it was produced).

```rust
〉"7fffffffffffffff" | into int -r 16 | into datetime | date to-record
╭────────────┬───────────╮
Expand All @@ -81,13 +84,69 @@ And finally, although not strictly required by the above fix, `<date> | date to-
╰───┴──────┴───────┴─────┴──────┴────────┴────────┴────────────┴──────────╯
```

## New XML format

New format for xml data created and accepted by `from xml` and `to xml` commands ([#7947](https://github.com/nushell/nushell/pull/7947)).

Commands `from xml` and `to xml` now use format where each xml entry is represented by a single `{tag: <tag name> attributes: <tag attributes> content: [<child entries>]}` record. Special xml entries also use this record, replacing irrelevant fields with `null` for easier use.

Reading some simple xml:

```rust
〉'<release>
<project repo="https://github.com/nushell/nushell">nushell</project>
<version>0.77</version>
<message>Now with better xml!</message>
</release>' | from xml
╭────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ tag │ release │
│ attributes │ {record 0 fields} │
│ │ ╭───┬─────────┬───────────────────────────────────────────────┬───────────────────────────────────────────╮ │
│ content │ │ # │ tag │ attributes │ content │ │
│ │ ├───┼─────────┼───────────────────────────────────────────────┼───────────────────────────────────────────┤ │
│ │ │ 0 │ project │ ╭──────┬────────────────────────────────────╮ │ ╭───┬─────┬────────────┬─────────╮ │ │
│ │ │ │ │ │ repo │ https://github.com/nushell/nushell │ │ │ # │ tag │ attributes │ content │ │ │
│ │ │ │ │ ╰──────┴────────────────────────────────────╯ │ ├───┼─────┼────────────┼─────────┤ │ │
│ │ │ │ │ │ │ 0 │ │ │ nushell │ │ │
│ │ │ │ │ │ ╰───┴─────┴────────────┴─────────╯ │ │
│ │ │ 1 │ version │ {record 0 fields} │ ╭───┬─────┬────────────┬─────────╮ │ │
│ │ │ │ │ │ │ # │ tag │ attributes │ content │ │ │
│ │ │ │ │ │ ├───┼─────┼────────────┼─────────┤ │ │
│ │ │ │ │ │ │ 0 │ │ │ 0.77 │ │ │
│ │ │ │ │ │ ╰───┴─────┴────────────┴─────────╯ │ │
│ │ │ 2 │ message │ {record 0 fields} │ ╭───┬─────┬────────────┬────────────────╮ │ │
│ │ │ │ │ │ │ # │ tag │ attributes │ content │ │ │
│ │ │ │ │ │ ├───┼─────┼────────────┼────────────────┤ │ │
│ │ │ │ │ │ │ 0 │ │ │ Now with │ │ │
│ │ │ │ │ │ │ │ │ │ better xml! │ │ │
│ │ │ │ │ │ ╰───┴─────┴────────────┴────────────────╯ │ │
│ │ ╰───┴─────────┴───────────────────────────────────────────────┴───────────────────────────────────────────╯ │
╰────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

Creating a little html page. In case of `to xml` one can deviate from rigid structure and omit
empty fields of records:

```rust
〉{tag: html content: [
{tag: body content: [
{tag: h1 content: ['Hello from Nushell !']}
{tag: a attributes: {href: 'https://www.nushell.sh/'} content: ['Learn more here']}
{tag: p content: [$"Current time is (date now)"]}
]}
]} | to xml
<html><body><h1>Hello from Nushell !</h1><a href="https://www.nushell.sh/">Learn more here</a><p>Current time is Mon, 13 Mar 2023 21:20:56 +0300 (now)</p></body></html>
```

# Breaking changes

- `str trim` no longer has `--all`, `--both`, and `--format` flags. `str replace` should be an adequate replacement; please let us know if it is not ([#8205](https://github.com/nushell/nushell/pull/8205))
- The changes to timestamp handling noted above ([#8244](https://github.com/nushell/nushell/pull/8244)) can require code changes to existing scripts:
* Saved data containing the results of an old datetime-to-timestamp conversion will *not* deserialize correctly when read back by the current version of Nushell. In general, Nushell will produce incorrect datetime values without noting an error.
* `<int> | into datetime` now assumes nanosecond scaling for all timestamps. You must ensure all timestamps computed by your script or retrieved from external sources are scaled appropriately.
* `<date> | into int` can now fail, as noted above. You cannot rely on this operation to persist a arbitrary date.
- Saved data containing the results of an old datetime-to-timestamp conversion will *not* deserialize correctly when read back by the current version of Nushell. In general, Nushell will produce incorrect datetime values without noting an error.
- `<int> | into datetime` now assumes nanosecond scaling for all timestamps. You must ensure all timestamps computed by your script or retrieved from external sources are scaled appropriately.
- `<date> | into int` can now fail, as noted above. You cannot rely on this operation to persist a arbitrary date.
- The change to `from xml` and `to xml` commands noted above ([#7947](https://github.com/nushell/nushell/pull/7947)) will require to update scripts relying on old output/input format.
- `mkdir`, `cp`, `mv` and `rm` return `nothing`. Errors and actions with `--verbose` flag are printed to stderr instead ([#8014](https://github.com/nushell/nushell/pull/8014)).
- Plugin authors relying on `nu_protocol::Value` may need to update their code to account for a change to `Value::Error` ([#8375](https://github.com/nushell/nushell/pull/8375))

# Full changelog
Expand Down