none
Is Duration.ToText Broken? RRS feed

  • Question

  • Hello,

    When I try various format strings with Duration.ToText, I get the same output every time. It feels like Duration.ToText is ignoring its format string argument.

    = Duration.ToText(#duration(1, 1, 2, 1.525), "s") // 1.01:02:01.5250000
    = Duration.ToText(#duration(1, 1, 2, 1.525), "hh:mm") // 1.01:02:01.5250000
    = Duration.ToText(#duration(1, 1, 2, 1.525), "dd hh:mm") // 1.01:02:01.5250000
    = Duration.ToText(#duration(1, 1, 2, 1.525), "something made up") // 1.01:02:01.5250000

    Any ideas? Am I missing something here? :-)

    (I'm using Excel 2016 version 1807.)

    Thanks,
    Ben

    Monday, August 13, 2018 8:39 PM

Answers

  • Correction: we always compile against .NET 3.5, so Duration.ToText always ignores the format parameter. We're looking into it, as this seems to have been an accidental change introduced quite some time ago.

    Thanks for letting us know.

    Ehren

    Thursday, August 16, 2018 7:18 PM
    Owner

All replies

  • Hi Ben. It appears that the format parameter only works when you're running the M Engine in .NET 4 and above.

    Ehren

    Tuesday, August 14, 2018 9:02 PM
    Owner
  • Hi Ehren,

    It appears that the format parameter only works when you're running the M Engine in .NET 4 and above.

    What's weird is that the format parameter works fine for the other temporal types. For example "= Date.ToText(#date(2018, 12, 25), "m")" outputs "December 25".

    If the issue were caused by the presence of an old version of .Net, wouldn't all of the "ToText" methods not work correctly?

    Ben


    • Edited by Ben Programmer Thursday, August 16, 2018 7:53 PM fixing typo
    Wednesday, August 15, 2018 7:49 PM
  • Duration uses a .NET method (TimeSpan.ToString) to convert a duration to text. TimeSpan.ToString doesn't support a format parameter in .NET 3.5, so we ignore the format when we're running in that version of .NET.

    Date.ToText with a format uses a completely different .NET method, which is available in .NET 3.5.

    Ehren

    Wednesday, August 15, 2018 7:56 PM
    Owner
  • Correction: we always compile against .NET 3.5, so Duration.ToText always ignores the format parameter. We're looking into it, as this seems to have been an accidental change introduced quite some time ago.

    Thanks for letting us know.

    Ehren

    Thursday, August 16, 2018 7:18 PM
    Owner
  • Thanks, Ehren!
    Thursday, August 16, 2018 7:53 PM
  • Hi Ehren

    Came across the issue and found that thread :). It seems the option has been depreciated

    the doc. still ref. it though

    Hope this helps

    Sunday, June 7, 2020 5:58 PM
  • Thanks for the heads up. The documentation should have been updated, so I'll investigate why that's not the case. (You can see the latest documentation if you type = Duration.ToText into the product.)

    Ehren

    Monday, June 8, 2020 6:12 PM
    Owner