Repository navigation
Closed
Labels
polishthis problem makes nu feel unpolishedstatus:needs-core-team-attentionAn issue than needs the attention of other core-team membersstatus:needs-designthis feature requires design
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
polishthis problem makes nu feel unpolishedstatus:needs-core-team-attentionAn issue than needs the attention of other core-team membersstatus:needs-designthis feature requires design
Activity
stellarpower commentedon Jun 6, 2023
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"
amtoine commentedon Jun 7, 2023
@dmatos2012 @stellarpower
the expected behaviour can be obtained with something like
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 😮stellarpower commentedon Jun 7, 2023
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.
amtoine commentedon Jun 8, 2023
oooh i see what you meant, thanks for the clarification 😊
so yeah my solution is not that great because it outputs
stringg rather thandatetimes with a specific format 👍as you suggest, maybe a config option could be great? just as we have
config.table.modecurious to see what others think about this 😌
Taywee commentedon Jun 21, 2023
I would love this. I'm writing some
mpcstuff 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:dmatos2012 commentedon Jun 21, 2023
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
amtoine commentedon Jun 21, 2023
yeah i think this has been discussed in the Discord server today 😋
as we already have
date humanizeand this all boils down to a simple rendering thing, maybe the simplest would be todate humanizeto have the current format?Taywee commentedon Jun 21, 2023
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.
amtoine commentedon Jun 21, 2023
@Taywee
agree with the points you're making 👌
we tend to avoid adding to many config options, but maybe this one makes sense 😌
stellarpower commentedon Jun 22, 2023
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:
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
$someTableand whatever it is I prefer to happen happens.