Skip to content

Weird error when using into datetime #13280

Closed

Description

@freijon

Describe the bug

I get a weird error when I try to convert into a specific date:

"09.02.2024 11:06:11" | into datetime --format '%d.%m.%Y %T'
Error: nu::shell::cant_convert

  × Can't convert to could not parse as datetime using format '%d.%m.%Y %T'.
   ╭─[entry #14:1:25]
 1 │ "09.02.2024 11:06:11" | into datetime --format '%d.%m.%Y %T'
   ·                         ──────┬──────
   ·                               ╰── can't convert input is not enough for unique date and time to could not parse as datetime using format '%d.%m.%Y %T'
   ╰────
  help: you can use `into datetime` without a format string to enable flexible parsing

How to reproduce

run:

"09.02.2024 11:06:11" | into datetime --format '%d.%m.%Y %T'

Expected behavior

  1. convert to datetime (this should work?)
  2. if there is really a problem, show an error message that is understandable

Screenshots

No response

Configuration

key value
version 0.94.2
major 0
minor 94
patch 2
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.78.0 (9b00956e5 2024-04-29) (gentoo)
cargo_version cargo 1.78.0
build_time 2024-06-05 16:16:58 +02:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash, which
installed_plugins bin_reader

Additional context

No response

Activity

  1. added
    status:needs-triage
    on Jul 1, 2024
  2. fdncred commented on Jul 1, 2024

    @fdncred
    Contributor

    Agreed. That error message is terrible.

    I think the problem is that converting to datetime requires a timezone.

    ❯ "09.02.2024 11:06:11+0000" | into datetime --format '%d.%m.%Y %H:%M:%S%z'
    Fri, 9 Feb 2024 11:06:11 +0000 (4 months ago)
  3. kaathewisegit commented on Jul 1, 2024

    @kaathewisegit
    Contributor

    Was about to post this. The parse_from_str method fails without a timezone. What's weird is that into datetime uses CantConvert error for some reason.

    Also, in theory, into datetime can use NaiveDateTime for this. After all, it's already defaulting to the current timezone when inferring the format:

    ~> "09.02.2024 11:06:11" | into datetime
    Mon, 2 Sep 2024 11:06:11 +0300 (in 2 months)
  4. hqsz commented on Jul 3, 2024

    @hqsz
    Contributor

    I agree with upper opinions! i make simple PR to resolve this issue. I will receive a review on the direction of this patch.

  5. added a commit that references this issue on Jul 4, 2024
    d5e00c0
  6. added this to the v0.96.0 milestone on Jul 5, 2024
  7. added
    A:datetime-handling
    on Sep 2, 2024
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

    A:datetime-handlingstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions