Fable icon indicating copy to clipboard operation
Fable copied to clipboard

[JavaScript] Makes a pass on the implementation of `DateTime.ToString`

Open MangelMaxime opened this issue 1 year ago • 1 comments

The current implementation of DateTime.ToString is incorrect for the javascript target.

For example, it considers T and t format to be the same thing when it isn't in .NET.

Description

[<Fact>]
let ``test DateTime.ToString("d") works`` () =
    DateTime(2014, 9, 11, 16, 37, 11, 345).ToString("d")
    |> equal "9/11/2014"

[<Fact>]
let ``test DateTime.ToString("T") works`` () =
    DateTime(2014, 9, 11, 3, 37, 11, 345).ToString("T")
    |> equal "3:37:11 AM"

    DateTime(2014, 9, 11, 16, 37, 11, 345).ToString("T")
    |> equal "4:37:11 PM"

[<Fact>]
let ``test DateTime.ToString("t") works`` () =
    DateTime(2014, 9, 11, 3, 37, 11, 345).ToString("t")
    |> equal "3:37 AM"

    DateTime(2014, 9, 11, 16, 37, 11, 345).ToString("t")
    |> equal "4:37 PM"

Related information

  • Fable version: 4.9.0
  • Operating system

MangelMaxime avatar Jan 06 '24 15:01 MangelMaxime

Python implementation of DateTime.toString can serve as base for this improvements:

https://github.com/fable-compiler/Fable/blob/88003be9f12bdb7221cc47d9358065c3c382f26b/src/fable-library-py/fable_library/date.py#L450-L454

Test suite to pass can be found here (make sure to check with current main version for an up to date list)

https://github.com/fable-compiler/Fable/blob/cc064046505fc998ab10f1548098a69a3f766aa7/tests/Python/TestDateTime.fs#L35-L471

MangelMaxime avatar Jan 24 '24 22:01 MangelMaxime