Skip Menu |

This queue is for tickets about the DateTime-Format-ISO8601 CPAN distribution.

Report information
The Basics
Id: 125660
Status: resolved
Priority: 0/
Queue: DateTime-Format-ISO8601

People
Owner: Nobody in particular
Requestors: PERLANCAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Is there a plan to do formatting, format_datetime()?
Meanwhile, I'll be releasing DateTime::Format::ISO8601::Format to supply this functionality, but I'm hoping it's in DateTime::Format::ISO8601
I'd like to upvote for this request as it enables more refactoring possibility from the caller side, as well as reducing surprises. It's not uncommon that in a Web CMS of some sort, a DateTime object needs to be formatted in both machine-readable formats and human-readable format, sometimes in the same output. One use case of such is to produce a HTML <time> tag: <time datetime="2020-04-06T00:00:00+0800">Yesterday</time> Where the "datetime" attribute and the "Yesterday" should refer to the same moment, but in different formats. Having a `format_datetime` method in this module enables developers to pre-construct a formatter object in controller and pass it to template -- without having to do this in in template: if ($wanted_format eq "iso8601") { ... } else { ... } Arguably this is also not difficult as there is already a `iso8601` method defined in DateTime class -- and this where reducing surprises kicks in :) For new comers who are looking for "how to format DateTime as iso8601" in CPAN -- chances are they find DateTime::Format::ISO8601 before they read sufficient amount of documentation of DateTime. They may try to use DateTime::Format::ISO8601 first and be surprised that it cannot do the job. Perhaps I'm blind and not seeing drawbacks of adding the `format_datetime` method. -- let's discuss though. So that's my 2c.