Skip to content

Formatting TimeSpan with %A prints TotalMilliseconds instead of formatted TimeSpan #2409

Closed

Description

@Booksbaum

Description

printfn "%A" myTimeSpan prints TotalMilliseconds of myTimeSpan and not a readable TimeSpan format.

Repro code

let ts = TimeSpan(11, 57, 37)
printfn "%A" ts
printfn "%s" (ts.ToString())

(repl)

Expected and actual results

Actual Output:

43057000
11:57:37

Expected Output:

11:57:37
11:57:37

During runtime TimeSpan becomes just milliseconds -- which is printed without any additional formatting.
It's probably not even possible to format: Type information isn't available at runtime and it's just a number (the milliseconds). So it might not be possible to distinguish TimeSpan from just number. But it still bites me every time I want to print a TimeSpan for debugging...

Workaround: manually call ToString() on TimeSpan. But that's only possible when it's known to be a TimeSpan.

Related information

  • Versions:
    • Fable: 3.1.5
    • Repl: 3.1.5

Activity

  1. alfonsogarciacaro commented on Jul 12, 2021

    @alfonsogarciacaro
    Member

    As commented in several other issues, unfortunately print formatting is not the same as .NET and particularly %A doesn't really do anything atm. To be fix this I guess we'd have to use a proper type for TimeSpan instead of just erasing it into a number, which would require some work. For now, let's close this issue and consolidate it with #2408

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions