Skip to content

Inconsistencies with DateTime string formatting #2408

Closed

Description

@Booksbaum

Description

There are several inconsistencies with DateTime and different DateTimeKinds when formatting as string:

%A is different for Kind=Local and Kind=Utc

%A for a local DateTime formats the DateTime completely different from UTC DateTime

Repro code

let local = DateTime(2020, 02, 20, 20, 20, 20, DateTimeKind.Local)
let utc = DateTime(2020, 02, 20, 20, 20, 20, DateTimeKind.Utc)

printfn "local = %A" local
printfn "utc   = %A" utc

(repl)

Expected and actual results

Actual output:

local = 2/20/2020, 8:20:20 PM
utc = Thu, 20 Feb 2020 20:20:20 GMT

Expected output:
Both should be in similar format -- especially same culture format.

In .NET:

local = 2020-02-20 20:20:20
utc = 2020-02-20 20:20:20

(Tough I think it's reasonable to include some indication of timezone, like it's done in Fable with utc (even though utc is technically not a timezone... GMT <> UTC...))

%A and ToString() are different

Repro code

let dt = DateTime(2020, 02, 20, 20, 20, 20)
printfn "dt            = %A" dt
printfn "dt.ToString() = %s" (dt.ToString())

(repl)

Expected and actual results

Actual output:

dt = 2/20/2020, 8:20:20 PM
dt.ToString() = Thu Feb 20 2020 20:20:20 GMT+0100 (Central European Standard Time)

Expected output:
Both should be in same format, and probably not the overcomplex one of ToString without any formatters.
And both should use same culture formatting.

In .NET:

dt = 2020-02-20 20:20:20
dt.ToString() = 2020-02-20 20:20:20

Using a Utc DateTime results in more similar representations:

let dt = DateTime(2020, 02, 20, 20, 20, 20, DateTimeKind.Utc)
printfn "dt            = %A" dt
printfn "dt.ToString() = %s" (dt.ToString())

(repl)

Output:

dt = Thu, 20 Feb 2020 20:20:20 GMT
dt.ToString() = Thu Feb 20 2020 21:20:20 GMT+0100 (Central European Standard Time)

But oddly still not the same: Thu, 20 Feb vs Thu Feb 20 ...

Related information

  • Versions:
    • Fable: 3.1.5
    • Repl: 3.1.5
  • Local System Settings:
    • TimeZone: CET (Central European Time -- UTC + 1)
    • date/time formatting: yyyy-MM-dd HH:mm:ss (2020-02-20 20:20:20)

Activity

  1. alfonsogarciacaro commented on Jul 12, 2021

    @alfonsogarciacaro
    Member

    Consolidated with #2409

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions