- What is the "serial comma"?
- SEE ALSO
- LICENSE AND COPYRIGHT
DateTime::Format::Human::Duration::Simple - Get a locale specific string describing the span of a given datetime duration.
use DateTime::Format::Human::Duration::Simple; use DateTime; my $from = DateTime->now; my $to = $from->clone->add( years => 1, months => 2, days => 3, hours => 4, minutes => 5, seconds => 6, ); my $duration = DateTime::Format::Human::Duration::Simple->new( from => $from, # required to => $to, # required # locale => 'en', # optional, default is 'en' (English) # serial_comma => 1, # optional, default is 1 (true) ); say $duration->formatted; # 1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds
This is a simple class for getting a localized string representing the duration between two DateTime objects.
This class is inspired by DateTime::Format::Human::Duration, and shares its namespace. I feel, however, that DateTime::Format::Human::Duration is a bit "heavy", and it's not updated very often. I also don't like its interface, so I created this class for an alternative that better suited me. If it will suit others, I don't know (or care), but there's always nice with alternatives. :)
Constructs a new DateTime::Format::Human::Duration::Simple object;
my $duration = DateTime::Format::Human::Duration::Simple->new( from => DateTime->new( ... ), # required to => DateTime->new( ... ), # required locale => 'de', # optional (default = 'en') # serial_comma => 1, # optional, default is 1 (true) );
Returns the current DateTime::Duration object, which is used by this class behind the scenes to generate the localized output.
Returns the locale specific string describing the span of the duration in question.
The "serial comma", also called the "oxford comma", is an optional comma before the word "and" (and/or other separating words) at the end of the list. Consider not using a serial comma:
1 hour, 2 minutes and 3 seconds
...vs. using a serial comma:
1 hour, 2 minutes, and 3 seconds
This value is defined per locale, i.e. from what's most normal (...) in each locale, but you can override when generating an instance of this class;
my $human = DateTime::Format::Human::Duration::Simple->new( from => $from_datetime, to => $to_datetime, serial_comma => 0, # turn it off for all locales );
You can read more about the serial comma on Wikipedia.
<toreau at gmail.com>
Please report any bugs or feature requests to the web interface at https://rt.cpan.org/Dist/Display.html?Name=DateTime-Format-Human-Duration-Simple
You can find documentation for this module with the perldoc command.
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
The MIT License (MIT)
Copyright (c) 2015 Tore Aursand
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.