Skip to content

deprecate --format and --list in into datetime#10017

Merged
fdncred merged 6 commits intonushell:mainfrom
amtoine:deprecate-into-datetime-format
Aug 17, 2023
Merged

deprecate --format and --list in into datetime#10017
fdncred merged 6 commits intonushell:mainfrom
amtoine:deprecate-into-datetime-format

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Aug 15, 2023

related to

Description

this PR

  • prints a colorful warning when a user uses either --format or --list on into datetime
  • does NOT remove the features for now, i.e. the two options still work
  • redirect to the format date command instead

i propose to

  • land this now
  • prepare a removal PR right after this
  • land the removal PR in between 0.84 and 0.85

User-Facing Changes

into datetime --format and into datetime --list will be deprecated in 0.85.

how it looks

  • into datetime --list in the REPL
> into datetime --list | first
Error:   × Deprecated option
   ╭─[entry #1:1:1]
 1  into datetime --list | first
   · ──────┬──────
   ·       ╰── `into datetime --list` is deprecated and will be removed in 0.85
   ╰────
  help: see `format datetime --list` instead


╭───────────────┬────────────────────────────────────────────╮
 Specification  %Y                                         
 Example        2023                                       
 Description    The full proleptic Gregorian year,         
                zero-padded to 4 digits.                   
╰───────────────┴────────────────────────────────────────────╯
  • into datetime --list in a script
> nu /tmp/foo.nu
Error:   × Deprecated option
   ╭─[/tmp/foo.nu:4:1]
 4  #
 5  into datetime --list | first
   · ──────┬──────
   ·       ╰── `into datetime --list` is deprecated and will be removed in 0.85
   ╰────
  help: see `format datetime --list` instead


╭───────────────┬────────────────────────────────────────────╮
 Specification  %Y                                         
 Example        2023                                       
 Description    The full proleptic Gregorian year,         
                zero-padded to 4 digits.                   
╰───────────────┴────────────────────────────────────────────╯
  • help into datetime

baz

Tests + Formatting

After Submitting

@amtoine amtoine added the category:deprecation Related to the deprecation of commands/features/options label Aug 15, 2023
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 15, 2023

I like it but don't think we can move forward with it unless it respects use_ansi_coloring. If use_ansi_coloring is false, all colors need to be removed. Some people have terminals that don't support coloring, believe it or not.

@sholderbach was also working on a ShellWarning system, although I'm not sure of it's status.

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Aug 15, 2023

I like it but don't think we can move forward with it unless it respects use_ansi_coloring. If use_ansi_coloring is false, all colors need to be removed. Some people have terminals that don't support coloring, believe it or not.

very good catch 👏 👏
should be better with 848344c 👍

@sholderbach was also working on a ShellWarning system, although I'm not sure of it's status.

i'd be happy to use a better and more clever system 😌
this is my quick and dirty proposal for now 😉

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Aug 16, 2023

thanks to @kubouch expertise, i've switched to using report_error and a GenericError to have pretty errors with span information 😋

@amtoine amtoine requested a review from fdncred August 16, 2023 21:02
Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

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

I think this is good for --options until we can get ShellWarning up and running, assuming we go that direction. I'm fine with landing this for now.

this avoids creating a working_set manually.
@amtoine amtoine force-pushed the deprecate-into-datetime-format branch from dc2f814 to c9ffc56 Compare August 17, 2023 16:36
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Aug 17, 2023

( i force pushed the last commit only immediately to amend dc2f814 with a Clippy fix )

@fdncred fdncred merged commit f33b60c into nushell:main Aug 17, 2023
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 17, 2023

Let's move forward with this and see how it goes.

@jmoore34
Copy link
Copy Markdown
Contributor

@amtoine My understanding is the --format flag of into datetime changes the input formatting, while date format only changes the output formatting. Feel free to correct me if I'm missing something.

https://github.com/amtoine/nushell/blob/c9ffc5696debd310c8aa4a81d85201fd5e7907ee/crates/nu-command/src/conversions/into/datetime.rs#L330C5-L334C71

// If input is not a timestamp, try parsing it as a string
    match input {
        Value::String { val, span } => {
            match dateformat {
                Some(dt) => match DateTime::parse_from_str(val, &dt.0)

From the documentation of parse_from_str:

Parses a string from a user-specified format into a DateTime value.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 17, 2023

Oh, input format. That would make a lot of sense then, but the problem with no one knowing understanding what it did was a problem. LOL. Maybe we revert this and chose something other than -f and be more specific about it being and input-format.

@amtoine amtoine deleted the deprecate-into-datetime-format branch August 19, 2023 08:33
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Aug 19, 2023

so do we revert this PR? before the release?

amtoine added a commit to amtoine/nushell that referenced this pull request Aug 19, 2023
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 19, 2023

Thanks for putting up a revert PR @amtoine. I'm still confused though because it seems that something isn't working right.

'20220604' | into datetime -f '%Y%m%d'

@jmoore34 Shouldn't this work or am I still missing the point to --format?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 19, 2023

Maybe we need a better datetime parsing create. Seems silly that the first one would work but the last one wouldn't. I just took off the %z and +0000.

 '20210227_135540+0000' | into datetime -f '%Y%m%d_%H%M%S%z'
Sat, 27 Feb 2021 13:55:40 +0000 (2 years ago)
 '20210227_135540' | into datetime -f '%Y%m%d_%H%M%S'
Error: nu::shell::cant_convert

  × Can't convert to could not parse as datetime using format '%Y%m%d_%H%M%S'.
   ╭─[entry #12:1:1]
 1 │ '20210227_135540' | into datetime -f '%Y%m%d_%H%M%S'
   ·                     ──────┬──────
   ·                           ╰── can't convert input is not enough for unique date and time to could not parse as datetime using format '%Y%m%d_%H%M%S'
   ╰────
  help: you can use `into datetime` without a format string to enable flexible parsing

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 19, 2023

Seems like dtparse may be better? https://github.com/bspeice/dtparse
There's a bajillion tests https://github.com/bspeice/dtparse/blob/master/src/tests/pycompat_parser.rs

I kind of like this one too https://github.com/waltzofpearls/dateparser

I guess my thought with these is to make it parse more date/datetime strings without having to use the --format since it seems kind of hit and miss.

fdncred pushed a commit that referenced this pull request Aug 19, 2023
#10055)

related to 
-
#10017 (comment)

# Description
this PR undeprecates `into datetime --format` and `into datetime
--list`.

this PR reverts commit f33b60c.

# User-Facing Changes

# Tests + Formatting

# After Submitting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:deprecation Related to the deprecation of commands/features/options

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants