Skip to content

into datetime only gets last part of date in output when on list/table #8549

Closed

Description

@dmatos2012

Describe the bug

Parsing a datetime when on a list/table, only uses the last part of the output. While it is still correct, I believe it would be a nicer to have a custom option to modify the output..

I Imagine that this has been done on purpose, specially to have a nice output for the ls commands and others that rely on datetimes, but maybe for my use case (and hope others), a nicer representation would be nice.

Most likely very unnecessary, but even taking a range of the datetimes given, an select the best fit format would be way nicer.

How to reproduce

❯ [1649203200000000000,1649289600000000000] | into datetime                                                                                                                                                                            
╭───┬────────────╮                                                                                                                                                                                                                     
│ 0 │ a year ago │                                                                                                                                                                                                                     
│ 1 │ a year ago │                                                                                                                                                                                                                     
╰───┴────────────╯  

Expected behavior

Output above is not very useful, specially if a table consists of only daily values. A nicer output could be

❯ [1649203200000000000,1649289600000000000] | into datetime                                                                                                                                                                            
╭───┬────────────╮                                                                                                                                                                                                                     
│ 0 │ 2022-04-06 │                                                                                                                                                                                                                     
│ 1 │ 2022-04-07│                                                                                                                                                                                                                     
╰───┴────────────╯  

Or something like that :)

Screenshots

No response

Configuration

key value
version 0.77.2
branch main
commit_hash ef7fbf4
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
build_time 2023-03-17 16:55:09 +01:00
build_rust_channel release
features default, zip
installed_plugins from parquet

Additional context

No response

Activity

  1. added
    polish
    on Mar 21, 2023
  2. stellarpower commented on Jun 6, 2023

    @stellarpower

    I came across this myself; I'm brand new to nu, and one answer I had was that this decision was based on making the shell easy to use interactively. Whilst this does work nicely for casual use of e.g. ls, when working with e.g. CSV or JSON files, or trying to delve into the filesystem, the phraseology like "a week ago" is next to useless. As an example, I was simply trying to locate the most recently edited file in a directory - I can sort the table, but then what date this actually was is presented exactly the same as the rest. So definitely should be a setting I could tune easily.

    Suggest possibly changing the bug title - e.g. "Allow configuring DateTime output format in table or list"

  3. amtoine commented on Jun 7, 2023

    @amtoine
    Member

    @dmatos2012 @stellarpower

    the expected behaviour can be obtained with something like

    [1649203200000000000, 1649289600000000000] | into datetime | each { date format "%Y-%m-%d" }

    does that solve the issue? 😋
    because, in the end, i think datetimes are only relative to the current one, this is why it displays like this 😮

  4. stellarpower commented on Jun 7, 2023

    @stellarpower

    That doesn't solve the issue for me - as now I have a list of strings. I'd have to re-parse that to manipulate it as a datetime, which then makes it too hacky to bother using nushell for this task.

    As I see it, this is a problem with output formatting, and not the internal representation. I think something like you have suggested would make sense, but as a config item, so that I can specify how dates should be presented in the prompt to me by default (or better, in certain scenarios). I don't want to modify my code, that should still work with the canonical format for DateTimes, but I do want the output to the terminal to be configured to be easier to read. Granted I can append this every single time for interactive use, but I don;t think it would handle non-datetime fields, and would become annoying, and I imagine this should properly belong as a config item so that it can be specified once and apply automatically.

    I also don't think the relativity is a factor here - if I go into a project I was working on from 01/05/23 to 31/05/23, then with absolute dates the formatter would still just print "May" - making it impossible to try and see when I last changed some source code file e.g. Or if I used this to manage some log files, I would have lines of "a month ago" then "a week ago" then "yesterday" etc. - so had my system been attacked say 10 days ago, the window I'd be trying to look for other evidence would be enormous because I can't see what I'm doing when I sort them and look in that period. So I think with relative or absolute timestamps internally, the problem is the same; this sort of output is helpful in some situations, especially scanning visually, but then too imprecise for other situations when I want to filter or sort by date.

  5. amtoine commented on Jun 8, 2023

    @amtoine
    Member

    oooh i see what you meant, thanks for the clarification 😊

    so yeah my solution is not that great because it outputs stringg rather than datetimes with a specific format 👍

    as you suggest, maybe a config option could be great? just as we have config.table.mode
    curious to see what others think about this 😌

  6. added
    status:needs-design
    status:needs-core-team-attention
    on Jun 8, 2023
  7. Taywee commented on Jun 21, 2023

    @Taywee
    Contributor

    I would love this. I'm writing some mpc stuff to work with music playlists, and the ability to output all my music as a nice workable table would be amazing, but having the "Album release date" columns all showing things like "10 years ago" and such is less than useful:

    > mpc listall | where albumartist =~ '(?i)one thousand lucky cranes' | sort-by date track | select artist album track title date genre file | table
    ╭───┬──────────────────────┬──────────────────────┬───────┬───────┬──────────────┬────────────┬──────────────────────╮
    │ # │        artist        │        album         │ track │ title │     date     │   genre    │         file         │
    ├───┼──────────────────────┼──────────────────────┼───────┼───────┼──────────────┼────────────┼──────────────────────┤
    │ 0 │ one thousand lucky   │ one thousand lucky   │     1 │ No.1  │ 10 years ago │ Electronic │ one thousand lucky   │
    │   │ cranes               │ cranes               │       │       │              │            │ cranes/one thousand  │
    │   │                      │                      │       │       │              │            │ lucky cranes/01      │
    │   │                      │                      │       │       │              │            │ No.1.opus            │
    │ 1 │ one thousand lucky   │ one thousand lucky   │     2 │ No.2  │ 10 years ago │ Electronic │ one thousand lucky   │
    │   │ cranes               │ cranes               │       │       │              │            │ cranes/one thousand  │
    │   │                      │                      │       │       │              │            │ lucky cranes/02      │
    │   │                      │                      │       │       │              │            │ No.2.opus            │
    │ 2 │ one thousand lucky   │ one thousand lucky   │     3 │ No.3  │ 10 years ago │ Electronic │ one thousand lucky   │
    │   │ cranes               │ cranes               │       │       │              │            │ cranes/one thousand  │
    │   │                      │                      │       │       │              │            │ lucky cranes/03      │
    │   │                      │                      │       │       │              │            │ No.3.opus            │
    │ 3 │ one thousand lucky   │ one thousand lucky   │     4 │ No.4  │ 10 years ago │ Electronic │ one thousand lucky   │
    │   │ cranes               │ cranes               │       │       │              │            │ cranes/one thousand  │
    │   │                      │                      │       │       │              │            │ lucky cranes/04      │
    │   │                      │                      │       │       │              │            │ No.4.opus            │
    │ 4 │ one thousand lucky   │ I                    │     1 │ I     │ 10 years ago │ Electronic │ one thousand lucky   │
    │   │ cranes               │                      │       │       │              │            │ cranes/I/01 I.opus   │
    ╰───┴──────────────────────┴──────────────────────┴───────┴───────┴──────────────┴────────────┴──────────────────────╯
    
  8. dmatos2012 commented on Jun 21, 2023

    @dmatos2012
    ContributorAuthor

    It seems that people would like this, I think it would be nice to maybe know what the core team thinks about this, and whether a PR would be taken regarding this topic.

    Because I know that we do not like adding flags to the commands, so just maybe a rough idea of how this can be achieved, and perhaps I could send a PR implementing that idea. :D @amtoine

  9. amtoine commented on Jun 21, 2023

    @amtoine
    Member

    yeah i think this has been discussed in the Discord server today 😋

    as we already have date humanize and this all boils down to a simple rendering thing, maybe the simplest would be to

    • have the precise raw format by default, e.g. something like
    > ls
    ╭───┬───────────┬──────┬───────────┬─────────────────────╮
    │ # │   name    │ type │   size    │      modified       │
    ├───┼───────────┼──────┼───────────┼─────────────────────┤
    │ 0 │ LICENSE   │ file │  34.3 KiB │ 2022-12-23 11:34:42 │
    │ 1 │ README.md │ file │  12.6 KiB │ 2023-06-12 19:49:28 │
    │ 2 │ documents │ dir  │   4.0 KiB │ 2023-02-19 11:29:42 │
    │ 3 │ downloads │ dir  │   4.0 KiB │ 2023-06-20 19:18:20 │
    │ 4 │ media     │ dir  │   4.0 KiB │ 2023-01-05 19:52:02 │
    │ 5 │ pkgs.toml │ file │ 114.7 KiB │ 2023-06-02 18:21:24 │
    │ 6 │ snap      │ dir  │   4.0 KiB │ 2023-01-03 11:02:26 │
    ╰───┴───────────┴──────┴───────────┴─────────────────────╯
    
    • and then you'd have to use date humanize to have the current format?
    > ls | update modified { date humanize }
    ╭───┬───────────┬──────┬───────────┬──────────────╮
    │ # │   name    │ type │   size    │   modified   │
    ├───┼───────────┼──────┼───────────┼──────────────┤
    │ 0 │ LICENSE   │ file │  34.3 KiB │ 6 months ago │
    │ 1 │ README.md │ file │  12.6 KiB │ a week ago   │
    │ 2 │ documents │ dir  │   4.0 KiB │ 4 months ago │
    │ 3 │ downloads │ dir  │   4.0 KiB │ a day ago    │
    │ 4 │ media     │ dir  │   4.0 KiB │ 5 months ago │
    │ 5 │ pkgs.toml │ file │ 114.7 KiB │ 2 weeks ago  │
    │ 6 │ snap      │ dir  │   4.0 KiB │ 5 months ago │
    ╰───┴───────────┴──────┴───────────┴──────────────╯
    
  10. Taywee commented on Jun 21, 2023

    @Taywee
    Contributor

    I'd like that. I think the default format should be one that shows all the relevant information.

    I think having a config option makes the most sense, because a lot of people would likely prefer the relative display format. Truthfully, it really comes down to context. Often when you want a date, you want to know "How long ago?" but other times, you really want "What specific date?" or "What day of the year did this happen?"

    For file times, knowing that something was last modified 6 months ago is probably useful enough, but if I'm looking at a dataset of historical events, knowing that D-Day was "79 years ago" isn't exactly what I'm looking for.

  11. amtoine commented on Jun 21, 2023

    @amtoine
    Member

    @Taywee
    agree with the points you're making 👌

    we tend to avoid adding to many config options, but maybe this one makes sense 😌

  12. stellarpower commented on Jun 22, 2023

    @stellarpower

    we tend to avoid adding to many config options, but maybe this one makes sense 😌

    Then as nushell is pretty functional, a proc that implements the default formatting might be a good way to go(?) That means it's doable in source code, and you don't need to have config values per se that handle every case; instead just a space where a user can customise the default for their shell themselves, maybe with some sensible examples in the docs. Hell, you could even do both; colour things in red if they look outdated, sky's your oyster:

    ╭───┬───────────┬──────┬───────────┬────────────────────────────────────────────────────────────────────────╮
    │ # │   name    │ type │   size    │   modified                                                             │                                                     
    ├───┼───────────┼──────┼───────────┼────────────────────────────────────────────────────────────────────────┤
    │ 0 │ LICENSE   │ file │  34.3 KiB │ 21/06/23 05:34 [⚠🛌🚫💤 ] (20 hours ago)  [🇺🇸: Sixth of twenty-oneuary ]│
    ╰───┴───────────┴──────┴───────────┴────────────────────────────────────────────────────────────────────────╯
    

    I think also the examples of updating the fields with are all perfectly good ways to go, for interactive use - i.e. I can set a useful default for me, and it's no harm to pipe things through one extra command on the odd occasion when I'm interacting with the system. But for developing scripts or for default use then I think the desired effect needs to happen without any extra explicit code at the callsite. I.e. I just type $someTable and whatever it is I prefer to happen happens.

  13. added this to the v0.82.0 milestone on Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    polishstatus:needs-core-team-attentionstatus:needs-design

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions