Closed autarch closed 3 years ago
From gugod@cpan.org (@gugod) on 2020-04-06 02:01:10 :
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 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.
Merged https://github.com/jhoblitt/DateTime-Format-ISO8601/pull/2 from Doug Bell
Migrated from rt.cpan.org #125660 (status was 'open')
Requestors:
From perlancar@cpan.org on 2018-06-23 08:54:47 :
Meanwhile, I'll be releasing DateTime::Format::ISO8601::Format to supply this functionality, but I'm hoping it's in DateTime::Format::ISO8601