DateTime-Format-Human-Duration-0.64/000755 000765 000024 00000000000 12744215264 020376 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/Build.PL000644 000765 000024 00000001062 12464635612 021673 0ustar00mstratmanstaff000000 000000 use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'DateTime::Format::Human::Duration', license => 'perl', dist_author => 'Daniel Muey ', dist_version_from => 'lib/DateTime/Format/Human/Duration.pm', build_requires => { 'Test::More' => 0, 'File::Spec' => 0, 'FindBin' => 0, }, requires => { }, add_to_cleanup => [ 'DateTime-Format-Human-Duration-*' ], ); $builder->create_build_script(); DateTime-Format-Human-Duration-0.64/Changes000644 000765 000024 00000005674 12744215241 021700 0ustar00mstratmanstaff000000 000000 Revision history for DateTime-Format-Human-Duration 0.64 Thu Jul 21 13:55:00 CDT 2016 * Updated to reflect recommendation in comment on pull #7 0.63 Thu Jul 21 13:47:16 CDT 2016 * Added compatibility with newer DateTime::Locale versions, for RT #108601 via https://github.com/mstratman/DateTime-Format-Human-Duration/pull/7 0.62 Thu Feb 5 03:45:30 CST 2015 * Added 'ko' localization (Keedi Kim ) https://github.com/mstratman/DateTime-Format-Human-Duration/pull/4 * Added 'ja' localization (Tomohiro Hosaka ) https://github.com/mstratman/DateTime-Format-Human-Duration/pull/3 0.61 Tue Jan 15 12:51:07 CST 2013 * Added 'significant_units' parameter (Tom Hukins). https://github.com/mstratman/DateTime-Format-Human-Duration/pull/2 0.60 Tue Jul 31 13:42:37 CDT 2012 * Added 'units' and 'precision' arguments (Stephan ) https://rt.cpan.org/Ticket/Display.html?id=76497 * Deprecated get_human_span_from_units_array() * Added get_human_span_from_units(), which should provide an alternative to get_human_span_from_units_array(), allowing you to determine whether the duration is positive or negative. https://rt.cpan.org/Ticket/Display.html?id=74923 It also works correctly with 'units' and 'precision' whereas get_human_span_from_units_array() would not. 0.52 Mon Jul 30 15:20:21 CDT 2012 * Skip one of the 01.methods.t tests until we can figure out a way to properly test it. 0.51 Thu Jul 5 08:35:45 CDT 2012 * Moved author tests to xt to avoid failed installations. 0.50 Tue Jul 3 14:22:49 CDT 2012 * Added 'it' localization (Aldo Calpini ) https://rt.cpan.org/Ticket/Display.html?id=76503 0.40 Wed Apr 11 21:46:08 CDT 2012 * Simplified version number scheme to ordinary decimal. * Minor POD changes * Fixed 02.array.t (hopefully) to actually use nb.pm and to pass when DateTime is not installed. 0.0.3 Tue Apr 10 20:37:18 CDT 2012 * Updated manifest - 0.0.2 was missing some needed files. Big whoops! 0.0.2 Tue Apr 10 20:08:34 2012 * Put the project on github so others can more easily add new locales or fix issues: https://github.com/mstratman/DateTime-Format-Human-Duration * Added .de locale (stefanos@cpan.org) https://rt.cpan.org/Ticket/Display.html?id=66248 * Fix for bad second counting in test (david.storrs@gmail.com) https://rt.cpan.org/Ticket/Display.html?id=66973 * Workaround applied to tests for counting issue: https://rt.cpan.org/Ticket/Display.html?id=52920 https://rt.cpan.org/Ticket/Display.html?id=71260 * Added failing TODO test for outstanding issue: https://rt.cpan.org/Ticket/Display.html?id=74923 0.0.1 Sun Mar 16 10:54:08 2008 * Initial release. DateTime-Format-Human-Duration-0.64/lib/000755 000765 000024 00000000000 12744215264 021144 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/Makefile.PL000644 000765 000024 00000001453 12464635612 022355 0ustar00mstratmanstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'DateTime::Format::Human::Duration', AUTHOR => 'Daniel Muey ', VERSION_FROM => 'lib/DateTime/Format/Human/Duration.pm', ABSTRACT_FROM => 'lib/DateTime/Format/Human/Duration.pm', PL_FILES => {}, BUILD_REQUIRES => { 'Test::More' => 0, 'File::Spec' => 0, 'FindBin' => 0, }, PREREQ_PM => { }, META_MERGE => { resources => { repository => 'https://github.com/mstratman/DateTime-Format-Human-Duration', }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'DateTime-Format-Human-Duration-*' }, ); DateTime-Format-Human-Duration-0.64/MANIFEST000644 000765 000024 00000001422 12744215264 021526 0ustar00mstratmanstaff000000 000000 Build.PL Changes lib/DateTime/Format/Human/Duration.pm lib/DateTime/Format/Human/Duration/Locale.pm lib/DateTime/Format/Human/Duration/Locale/de.pm lib/DateTime/Format/Human/Duration/Locale/es.pm lib/DateTime/Format/Human/Duration/Locale/fr.pm lib/DateTime/Format/Human/Duration/Locale/it.pm lib/DateTime/Format/Human/Duration/Locale/ja.pm lib/DateTime/Format/Human/Duration/Locale/ko.pm lib/DateTime/Format/Human/Duration/Locale/pt.pm Makefile.PL MANIFEST This list of files README t/00.load.t t/01.methods.t t/02.array.t t/lib/DateTime/Format/Human/Duration/Locale/nb.pm xt/perlcritic.t xt/pod-coverage.t xt/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) DateTime-Format-Human-Duration-0.64/META.json000644 000765 000024 00000002110 12744215264 022011 0ustar00mstratmanstaff000000 000000 { "abstract" : "Get a locale specific string describing the span of a given duration", "author" : [ "Daniel Muey " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.72, CPAN::Meta::Converter version 2.133380", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "DateTime-Format-Human-Duration", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "File::Spec" : "0", "FindBin" : "0", "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "https://github.com/mstratman/DateTime-Format-Human-Duration" } }, "version" : "0.64" } DateTime-Format-Human-Duration-0.64/META.yml000644 000765 000024 00000001220 12744215264 021642 0ustar00mstratmanstaff000000 000000 --- abstract: 'Get a locale specific string describing the span of a given duration' author: - 'Daniel Muey ' build_requires: File::Spec: 0 FindBin: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.72, CPAN::Meta::Converter version 2.133380' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: DateTime-Format-Human-Duration no_index: directory: - t - inc requires: {} resources: repository: https://github.com/mstratman/DateTime-Format-Human-Duration version: 0.64 DateTime-Format-Human-Duration-0.64/README000644 000765 000024 00000032740 12744214227 021262 0ustar00mstratmanstaff000000 000000 NAME DateTime::Format::Human::Duration - Get a locale specific string describing the span of a given duration SYNOPSIS use DateTime; use DateTime::Format::Human::Duration my $span = DateTime::Format::Human::Duration->new(); my $dur = $dta - $dtb; print $span->format_duration($dur); # 1 year, 2 months, 3 minutes, and 1 second print $span->format_duration_between($dta, $dtb); # 1 year, 2 months, 3 minutes, and 1 second DESCRIPTION Get a localized string representing the duration. For example: 1 second 2 minutes and 3 seconds 3 weeks, 1 day, and 5 seconds 4 years, 1 month, 2 days, 6 minutes, 1 second, and 345000028 nanoseconds INTERFACE new() Create span object, no args format_duration() First argument is a DateTime::Duration object After that you can optionally pass some standard args as a hash as described below format_duration_between() First two args are DateTime objects After that you can optionally pass some standard args as a hash as described below standard args 1. 'locale' locale of the $dt object will be used if you do not specify this Valid values are a string of the locale (E.g 'fr'), a DateTime object, or a DateTime object's 'locale' key. 2. Since we're working with 2 DateTime objects of known points we can have past and future tenses. * past String to use if duration is past tense. Can have a sprintf '%s' or else is prepended with a trailing space. * future String to use if duration is future tense. Can have a sprintf '%s' or else is prepended with a trailing space. * no_time Override the 'no_time' in the locale hash. If duration is baseless (IE ambiguous) then 'past' and 'future' is used based on if $dur->in_units has negatives or not. Also by nature it's not split into type groups: An example is DateTime::Duration->new('seconds'=> 62) Will result in '62 seconds' not '1 minute and 2 seconds' For more sane results always be specific by using 2 datetime object to get a duration object print $dt->format_duration_between( $dta, $dtb, 'past' => 'Your account expired %s ago.', 'future' => 'Your account expires in %s.', 'no_time'=> 'Your account just expired.', ); This facilitates, for example, this Locale::Maketext vernacular which becomes: 'Your account [duration,_1,_2,expired %s ago,expires in,just expired].' => '[Votre compte [duration,_1,_2,a expiré il ya,expire dans,vient d'expirer].' 3. Time Resolution and Units * units Specify units to format duration with. Arguments will be passed to DateTime::Format's in_unit() method. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); my $s = $fmt->format_duration($d, 'units' => [qw/years months days/] ); # $s == '1 year, 7 months, and 16 days' Possible values include: years months weeks days hours minutes seconds nanoseconds * precision By default, the duration will be formatted using nanosecond resolution. Resolution can be reduced by passing 'years', 'months', 'weeks', 'days', 'hours', 'minutes', or 'seconds' to the 'precision' argument. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); print $fmt->format_duration($d); # '1 year, 7 months, 2 weeks, 2 days, 13 hours, 43 minutes, and 15 seconds' print $fmt->format_duration($d, 'precision' => 'days'); # '1 year, 7 months, 2 weeks, and 2 days' * significant_units By default, the duration will be formatted using all specified units. To restrict the number of units output, set this to a value of one or more. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); print $fmt->format_duration($d, 'significant_units' => 1); # '3 days' print $fmt->format_duration($d, 'significant_units' => 2); # '3 days and 10 hours' print $fmt->format_duration($d, 'significant_units' => 3); # '3 days, 10 hours, and 27 minutes' LOCALIZATION Localization is provided by the included DateTime::Format::Human::Duration::Locale modules. Included are DateTime::Format::Human::Duration::Locale::es, DateTime::Format::Human::Duration::Locale::fr, DateTime::Format::Human::Duration::Locale::pt, DateTime::Format::Human::Duration::Locale::de, DateTime::Format::Human::Duration::Locale::it More will be included as time permits/folks volunteer/CLDR becomes an option They are setup this way: DateTime::Format::Human::Duration::Locale::XYZ where 'XYZ' is the ISO code of DateTime::Locale It can have one of 2 functions: get_human_span_hashref() Takes no arguments, should return a hashref of this structure: sub get_human_span_hashref { return { 'no_oxford_comma' => 1, 'no_time' => 'pas le temps', 'and' => 'et', 'year' => 'an', 'years' => 'ans', 'month' => 'mois', 'months' => 'mois', 'week' => 'semaine', 'weeks' => 'semaines', 'day' => 'jour', 'days' => 'jours', 'hour' => 'heure', 'hours' => 'heures', 'minute' => 'minute', 'minutes' => 'minutes', 'second' => 'seconde', 'seconds' => 'seconds', 'nanosecond' => 'nanoseconde', 'nanoseconds' => 'nanosecondes', }; } get_human_span_from_units() Try to use get_human_span_hashref() if the locale allows for it since it's much easier. If you cannot, however, then this will give you the maximum level of configurability. This function receives a hashref of duration values, and a hashref of the standard args. It should return the localized string. sub get_human_span_from_units { my ($duration_values_hr, $args_hr) = @_; ...; return $string; # 1 year, 2days, 4 hours, and 17 minutes } Please see the example in `t/lib/DateTime/Format/Human/Duration/Locale/nb.pm'. LOCALIZATION of DateTime::Format modules DateTime does an excellent job at implementing localization. Often DateTime::Format based class's either don't support localization or they implement it haphazardly and inconsistently. With this module I hope to model a localization scheme that is inline with DateTime and is consistent and reuseable between based classes. The idea is to determine the locale to use based on a DateTime object. XYZ::Locale should handle looking up (and caching if appropriate) the locale and loading the necessary locale module XYZ::Locale::fr The specific locale module holds the data and possibly logic necessary to do what XYZ does in the vernacular of the given locale. TODO Eventually the generic logic will be re-broken out into its own module for re-use by your class and I'll have more detailed POD about how to do it. In the meantime if you're interested please contact me and I'd be happy to help and/or expediate this TODO. Also, Dave Rolksy has mentioned to me that this sort of locale data might be appropriate for DateTime::Locale directly from CLDR. If that happens this module will be changed to use that if possible. FAQ Why would I want to use this? So you can localize your application's output of time periods without having to do a lot of logic each time you wanted to say it. Locale::Maketext::Utils has/will have a duration() bracket notation method which prompted this module's existence duration() was prompted by its datetime() brother, all of which uses the most excellent DateTime project! Why did my duration say '62 seconds' instead of '1 minute and 2 seconds' Because you used an ambiguous duration (one without a base) so there is no way to apply date math and accurately represent the number of each given item in that duration since it may or may not span leap-[second, days, years, etc..] In other words do this (so that your duration can be specifically calculated): $dtb = $dta->clone->add('seconds'=> 62); my $duration = $dta - $dtb; # has a base, its not ambiguous print $span->format_duration($duration); # 1 minutes and 2 seconds not this: my $duration = DateTime::Duration->new('seconds'=> 62); # no base, it is ambiguous print $span->format_duration($duration); # 62 seconds Note format_duration_between(), does not suffer from this since we're using a specific DateTime object already. print $span->format_duration_between( $dt, $dt->clone()->add('seconds'=> 62) ); # 1 minute and 2 seconds Why do you put a comma before the 'and' in a group of more than 2 items? We want to use the so-called Oxford comma to avoid ambiguity. My DateTime::Format::Human::Duration::Locale::XX still outputs in English! That is because it defined neither the get_human_span_hashref() or the get_human_span_from_units() functions It must define one of them or defaults are used. Why didn't you just use 'DateTime::Format::Duration' Essencially DateTime::Format::Duration is an object representing a single strftime() type string to apply to any given duration. This is not flexible enough for the intent of this module. DateTime::Format::Duration is not a bad module its just for a different purpose than DateTime::Format::Human::Duration * It was not localizable You either got '2 days' or '1 days' which a) forces it to be in English and b) doesn't even make sense in English. You could get around that by adding logic each time you wanted to call it but that is just messy. * Had to keep an item even if it was zero If 'days' was in there you got '0 days', we only want items with a value to show. That'd also require a lot of logic each time you wanted to call which is again messy. * This module has no need for reparsing output back into an object Since the datetime info for 2 points in time are generally in a form easily rendered into a DateTime object it'd be silly to even attempt to store and parse the output of this module back into an object. Plus since it all depends on the locale it is in it'd be difficult. The purpose of DateTime::Format::Human::Duration was to generate a localized human language description of a duration without the caller needing to supply any logic. DIAGNOSTICS Throws no warnings or errors of its own CONFIGURATION AND ENVIRONMENT DateTime::Format::Human::Duration requires no configuration files or environment variables. DEPENDENCIES None. INCOMPATIBILITIES None reported. BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to `bug-datetime-format-span@rt.cpan.org', or through the web interface at http://rt.cpan.org. AUTHOR Daniel Muey `' LICENCE AND COPYRIGHT Copyright (c) 2008, Daniel Muey `'. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. DateTime-Format-Human-Duration-0.64/t/000755 000765 000024 00000000000 12744215264 020641 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/xt/000755 000765 000024 00000000000 12744215264 021031 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/xt/perlcritic.t000644 000765 000024 00000000466 12464635612 023366 0ustar00mstratmanstaff000000 000000 #!perl -T use Test::More; eval 'use Test::Perl::Critic'; plan skip_all => 'Test::Perl::Critic required for testing PBP compliance' if $@; plan skip_all => q($ENV{'do_perl_critic_tests'} must be true to run these 'development only' tests) if !$ENV{'do_perl_critic_tests'}; Test::Perl::Critic::all_critic_ok(); DateTime-Format-Human-Duration-0.64/xt/pod-coverage.t000644 000765 000024 00000000535 12464635612 023576 0ustar00mstratmanstaff000000 000000 #!perl -T use Test::More; eval 'use Test::Pod::Coverage 1.04'; plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage' if $@; Test::Pod::Coverage::pod_coverage_ok( "DateTime::Format::Human::Duration", { 'trustme' => [qr/^(new)$/,], } ); # Locale.pm, es.pm, and fr.pm don;t have POD # all_pod_coverage_ok(); done_testing(); DateTime-Format-Human-Duration-0.64/xt/pod.t000644 000765 000024 00000000214 12464635612 021777 0ustar00mstratmanstaff000000 000000 #!perl -T use Test::More; eval 'use Test::Pod 1.14'; plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@; all_pod_files_ok(); DateTime-Format-Human-Duration-0.64/t/00.load.t000644 000765 000024 00000000267 12464635612 022172 0ustar00mstratmanstaff000000 000000 use Test::More tests => 1; BEGIN { use_ok( 'DateTime::Format::Human::Duration' ); } diag( "Testing DateTime::Format::Human::Duration $DateTime::Format::Human::Duration::VERSION" ); DateTime-Format-Human-Duration-0.64/t/01.methods.t000644 000765 000024 00000011704 12464635612 022715 0ustar00mstratmanstaff000000 000000 use Test::More; use lib '../lib'; BEGIN { use_ok( 'DateTime::Format::Human::Duration' ); } diag( "Testing DateTime::Format::Human::Duration $DateTime::Format::Human::Duration::VERSION" ); SKIP: { eval 'use DateTime'; skip 'DateTime required for creating DateTime object and durations', 22 if $@; # Do setup my $time = time; my $dua = DateTime->from_epoch( 'epoch' => $time ); my $dub = DateTime->from_epoch( 'epoch' => $time, 'locale' => 'fr' )->add(seconds => 2); my $duc = $dua->clone->add( minutes => 1, seconds => 3 ); my $dud = $dua->clone->add(hours => 1, seconds => 25, nanoseconds => 445499897); my $due = $dua->clone->add(months => 9, days => 1, hours => 4, minutes => 17, seconds => 33, nanoseconds => 345000028); my $duf = $dua->clone->add( minutes => 1, seconds => 1 ); my $dura = $dua - $dua; my $durc = $dua - $dub; my $durd = $dub - $dua; my $dure = $dua - $duc; my $durf = $dua - $dud; my $durg = $dua - $due; # Start testing my $span = DateTime::Format::Human::Duration->new(); isa_ok($span, 'DateTime::Format::Human::Duration'); is( $span->format_duration($dura), 'no time', 'No difference w/ default no_time'); is( $span->format_duration($dura, 'no_time' => 'absolutely no time' ), 'absolutely no time', 'No difference w/ no_time'); is( $span->format_duration($dura, 'no_time' => '' ), '', 'No difference w/ empty no_time'); is( $span->format_duration($durc), '2 seconds', '1 value'); is( $span->format_duration_between($dub, $dua), '2 seconds', 'Reverse/Negative is still positive (not "no time")'); is( $span->format_duration_between($dua, $duf), '1 minute and 1 second', '2 (singular values)'); is( $span->format_duration($dure), '1 minute and 3 seconds', '2 values (mixed)' ); is( $span->format_duration($durf), '1 hour, 25 seconds, and 445499897 nanoseconds', '> 2 values (3)'); TODO: { local $TODO = "This doesn't work at 1343679514. Gives '2 days' instead of 1"; # Note: it works with 8 months, or 10 months. So perhaps it's somehow # related to rounding issues over multi-month durations? is( $span->format_duration($durg), '9 months, 1 day, 4 hours, 17 minutes, 33 seconds, and 345000028 nanoseconds', '> 2 values (5)'); }; is( $span->format_duration($durc, 'future' => 'Hello, You have %s left'), 'Hello, You have 2 seconds left', 'string with %s'); is( $span->format_duration($durc, 'future' => 'You have'), 'You have 2 seconds', 'string w/ out %s'); is( $span->format_duration_between($dua, $dub), '2 seconds', 'DateTime object method format_duration_between()'); is( $span->format_duration_between($dua, $duc, 'past'=>'Was done %s ago.','future' => 'Will be done in %s.'), 'Will be done in 1 minute and 3 seconds.','$a->format_duration_between($b): $a < $b = future'); is( $span->format_duration_between($duc, $dua, 'past'=>'Was done %s ago.','future' => 'Will be done in %s.'), 'Was done 1 minute and 3 seconds ago.','$a->format_duration_between($b): $a > $b = past'); is( $span->format_duration_between( $duc, $duc->clone()->add('seconds'=> 62) ), '1 minute and 2 seconds', 'clone exmple'); is( $span->format_duration( DateTime::Duration->new('seconds'=> 62) ), '62 seconds', 'Ambiguous duration (baseless)'); # test 'locale' key is( $span->format_duration($dure, 'locale' => 'fr'), '1 minute et 3 seconds', 'locale key as string format_duration()'); is( $span->format_duration($dure, 'locale' => $dub), '1 minute et 3 seconds', 'locale key as $DateTime obj format_duration()'); is( $span->format_duration($dure, 'locale' => $dub->{'locale'}), '1 minute et 3 seconds', 'locale key as $DateTime->{\'locale\'} format_duration()'); is( $span->format_duration_between($dub, $duc), '1 minute et 1 seconde', 'Object\'s locale used in format_duration_between()'); # test 'significant_units' is( $span->format_duration($dure, significant_units => 1), '1 minute', 'only show one significant unit' ); is( $span->format_duration($dure, significant_units => 99), '1 minute and 3 seconds', 'show up to 99 significant unit' ); is( $span->format_duration($dure, significant_units => 99, units => ['minutes']), '1 minute', 'show up to 99 significant units, with specific units' ); is( $span->format_duration($durf, significant_units => 1), '1 hour', 'show 1 unit of 3' ); is( $span->format_duration($durf, significant_units => 2), '1 hour and 25 seconds', 'show 2 units of 3' ); is( $span->format_duration($durf, significant_units => 3), '1 hour, 25 seconds, and 445499897 nanoseconds', 'show 3 units of 3' ); is( $span->format_duration($durf, significant_units => 3, units => ['hours','minutes']), '1 hour', '3 significant_units with specified units of hours and minutes' ); is( $span->format_duration($durf, significant_units => 3, units => ['hours','seconds']), '1 hour and 25 seconds', '3 significant_units with specified units of hours and seconds' ); }; done_testing(); DateTime-Format-Human-Duration-0.64/t/02.array.t000644 000765 000024 00000001274 12464635612 022372 0ustar00mstratmanstaff000000 000000 use Test::More; use lib 't/lib'; use DateTime::Format::Human::Duration; use FindBin qw($Bin); use File::Spec; BEGIN { push @INC, File::Spec->catfile($Bin, 'lib'); } my $fmt = DateTime::Format::Human::Duration->new; SKIP: { eval 'use DateTime'; skip 'DateTime required for creating DateTime object and durations', 2 if $@; my $dta = DateTime->now( locale => 'nb' ); my $dtb = $dta->clone->add( minutes => 1 ); my $dtc = $dta->clone->subtract( minutes => 1 ); is($fmt->format_duration_between($dta, $dtb, past => '%s ago', future => 'in %s'), '1mi ago'); is($fmt->format_duration_between($dta, $dtc, past => '%s ago', future => 'in %s'), 'in 1mi'); }; done_testing(); DateTime-Format-Human-Duration-0.64/t/lib/000755 000765 000024 00000000000 12744215264 021407 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/000755 000765 000024 00000000000 12744215264 023103 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/Format/000755 000765 000024 00000000000 12744215264 024333 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/Format/Human/000755 000765 000024 00000000000 12744215264 025403 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/Format/Human/Duration/000755 000765 000024 00000000000 12744215264 027170 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/Format/Human/Duration/Locale/000755 000765 000024 00000000000 12744215264 030367 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/t/lib/DateTime/Format/Human/Duration/Locale/nb.pm000644 000765 000024 00000002205 12464635612 031325 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::nb; use strict; use warnings; # TODO: find a way to test fake locales without using real codes. # i.e. if/when somebody adds a real NB locale, I don't want this to cause # issues. sub get_human_span_from_units { my ($duration_units, $args_hr) = @_; my %n = map { ($_ => abs $duration_units->{$_}) } keys %$duration_units; my $s = 'now'; if ($n{years}) { $s = $n{years} . "y"; } elsif ($n{months}) { $s = $n{months} . "mo"; } elsif ($n{weeks}) { $s = $n{weeks} . "w"; } elsif ($n{days}) { $s = $n{days} . "d"; } elsif ($n{hours}) { $s = $n{hours} . "h"; } elsif ($n{minutes}) { $s = $n{minutes} . "mi"; } elsif ($n{seconds}) { $s = "moments"; } my $past = grep { $_ < 0 } values %$duration_units; my $say = ''; if ($past && $args_hr->{past}) { $say = $args_hr->{past}; } elsif (! $past && $args_hr->{future}) { $say = $args_hr->{future}; } if ($say) { $s = $say =~ m{%s} ? sprintf($say, $s): "$say $s"; } return $s; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/000755 000765 000024 00000000000 12744215264 022640 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/000755 000765 000024 00000000000 12744215264 024070 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/000755 000765 000024 00000000000 12744215264 025140 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/000755 000765 000024 00000000000 12744215264 026725 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration.pm000644 000765 000024 00000041475 12744215251 027272 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration; use warnings; use strict; require DateTime::Format::Human::Duration::Locale; our $VERSION = '0.64'; use Carp qw/croak/; sub new { bless { 'locale_cache' => {} }, 'DateTime::Format::Human::Duration'; } sub format_duration_between { my ($span, $dt, $dtb, %args) = @_; my $dur = $dt - $dtb; if (!exists $args{'locale'}) { my $locale_obj = $dt->locale; if (UNIVERSAL::can($locale_obj, 'code')) { $args{'locale'} = $locale_obj->code; # DateTime::Locale v1 } else { $args{'locale'} = $locale_obj->id; # DateTime::Locale v0 } } return $span->format_duration($dur, %args); } sub format_duration { my ($span, $duration, %args) = @_; my @default_units = qw(years months weeks days hours minutes seconds nanoseconds); my @units = $args{'units'} ? @{ $args{'units'} } : @default_units; if ($args{'precision'}) { # Reduce time resolution to requested precision for (my $i = 0; $i < scalar(@units); $i++) { next unless ($units[$i] eq $args{'precision'}); splice(@units, $i + 1); } croak('Useless precision') unless (@units); } my @duration_vals = $duration->in_units( @units ); my $i = 0; my %duration_vals = map { ($_ => $duration_vals[$i++]) } @units; my %positive_duration_vals = map { ($_ => abs $duration_vals{$_}) } keys %duration_vals; my $say = ''; # $dta - $dtb: # if dta < dtb means past -> future (Duration units will have negatives) # else its either this absolute instant (no_time) or the past if ( grep { $_ < 0 } @duration_vals ) { if ( exists $args{'future'} ) { $say = $args{'future'} } } else { if ( exists $args{'past'} ) { $say = $args{'past'} } } #### ## this is essentially the hashref that is returned from DateTime::Format::Human::Duration::en::get_human_span_hashref() : # #### my $setup = { 'no_oxford_comma' => 0, 'no_time' => 'no time', # The wait will be $formatted_duration 'and' => 'and', 'year' => 'year', 'years' => 'years', 'month' => 'month', 'months' => 'months', 'week' => 'week', 'weeks' => 'weeks', 'day' => 'day', 'days' => 'days', 'hour' => 'hour', 'hours' => 'hours', 'minute' => 'minute', 'minutes' => 'minutes', 'second' => 'second', 'seconds' => 'seconds', 'nanosecond' => 'nanosecond', 'nanoseconds' => 'nanoseconds', }; my $locale = DateTime::Format::Human::Duration::Locale::calc_locale($span, $args{'locale'}); if($locale) { if ( ref $locale eq 'HASH' ) { %{ $setup } = ( %{ $setup }, %{ $locale }, ); } # get_human_span_from_units_array is deprecated, but we will still # support it. elsif ( my $get1 = $locale->can('get_human_span_from_units_array') ) { my @n = map { $positive_duration_vals{$_} } @default_units; return $get1->( @n, \%args ); } elsif ( my $get2 = $locale->can('get_human_span_from_units') ) { return $get2->( \%duration_vals, \%args ); } } my @parts; for my $unit (@units) { my $val = $positive_duration_vals{$unit}; next unless $val; my $setup_key = $unit; if ($val == 1) { $setup_key =~ s/s$//; } push(@parts, $val . ' ' . $setup->{$setup_key}); if (exists $args{'significant_units'}) { last if scalar(@parts) == $args{'significant_units'}; } } my $no_time = exists $args{'no_time'} ? $args{'no_time'} : $setup->{'no_time'}; return $no_time if !@parts; my $last = @parts > 1 ? pop(@parts): ''; ## We want to use the so-called Oxford comma to avoid ambiguity. ## For that reason we make locale's specifically tell us they do not want it. my $string = $setup->{'no_oxford_comma'} ? join(', ', @parts) . ($last ? " $setup->{'and'} $last" : '') : join(', ', @parts) . (@parts > 1 ? ',' : '') . ($last ? " $setup->{'and'} $last" : '') ; if ( $say ) { $string = $say =~ m{%s} ? sprintf($say, $string): "$say $string"; } return $string; } 1; __END__ =encoding utf8 =head1 NAME DateTime::Format::Human::Duration - Get a locale specific string describing the span of a given duration =head1 SYNOPSIS use DateTime; use DateTime::Format::Human::Duration my $span = DateTime::Format::Human::Duration->new(); my $dur = $dta - $dtb; print $span->format_duration($dur); # 1 year, 2 months, 3 minutes, and 1 second print $span->format_duration_between($dta, $dtb); # 1 year, 2 months, 3 minutes, and 1 second =head1 DESCRIPTION Get a localized string representing the duration. For example: 1 second 2 minutes and 3 seconds 3 weeks, 1 day, and 5 seconds 4 years, 1 month, 2 days, 6 minutes, 1 second, and 345000028 nanoseconds =head1 INTERFACE =head2 new() Create span object, no args =head2 format_duration() First argument is a DateTime::Duration object After that you can optionally pass some L as a hash as described below =head2 format_duration_between() First two args are DateTime objects After that you can optionally pass some L as a hash as described below =head2 standard args =over 4 =item 1. 'locale' locale of the $dt object will be used if you do not specify this Valid values are a string of the locale (E.g 'fr'), a DateTime object, or a DateTime object's 'locale' key. =item 2. Since we're working with 2 DateTime objects of known points we can have past and future tenses. =over 4 =item * past String to use if duration is past tense. Can have a sprintf '%s' or else is prepended with a trailing space. =item * future String to use if duration is future tense. Can have a sprintf '%s' or else is prepended with a trailing space. =item * no_time Override the 'no_time' in the locale hash. =back If duration is baseless (IE ambiguous) then 'past' and 'future' is used based on if $dur->in_units has negatives or not. Also by nature it's not split into type groups: An example is DateTime::Duration->new('seconds'=> 62) Will result in '62 seconds' not '1 minute and 2 seconds' For more sane results always be specific by using 2 datetime object to get a duration object print $dt->format_duration_between( $dta, $dtb, 'past' => 'Your account expired %s ago.', 'future' => 'Your account expires in %s.', 'no_time'=> 'Your account just expired.', ); This facilitates, for example, this L vernacular which becomes: 'Your account [duration,_1,_2,expired %s ago,expires in,just expired].' => '[Votre compte [duration,_1,_2,a expiré il ya,expire dans,vient d'expirer].' =item 3. Time Resolution and Units =over 4 =item * units Specify units to format duration with. Arguments will be passed to DateTime::Format's in_unit() method. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); my $s = $fmt->format_duration($d, 'units' => [qw/years months days/] ); # $s == '1 year, 7 months, and 16 days' Possible values include: years months weeks days hours minutes seconds nanoseconds =item * precision By default, the duration will be formatted using nanosecond resolution. Resolution can be reduced by passing 'years', 'months', 'weeks', 'days', 'hours', 'minutes', or 'seconds' to the 'precision' argument. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); print $fmt->format_duration($d); # '1 year, 7 months, 2 weeks, 2 days, 13 hours, 43 minutes, and 15 seconds' print $fmt->format_duration($d, 'precision' => 'days'); # '1 year, 7 months, 2 weeks, and 2 days' =item * significant_units By default, the duration will be formatted using all specified units. To restrict the number of units output, set this to a value of one or more. Example: my $fmt = DateTime::Format::Human::Duration->new(); my $d = DateTime::Duration->new(...); print $fmt->format_duration($d, 'significant_units' => 1); # '3 days' print $fmt->format_duration($d, 'significant_units' => 2); # '3 days and 10 hours' print $fmt->format_duration($d, 'significant_units' => 3); # '3 days, 10 hours, and 27 minutes' =back =back =head1 LOCALIZATION Localization is provided by the included DateTime::Format::Human::Duration::Locale modules. Included are DateTime::Format::Human::Duration::Locale::es, DateTime::Format::Human::Duration::Locale::fr, DateTime::Format::Human::Duration::Locale::pt, DateTime::Format::Human::Duration::Locale::de, DateTime::Format::Human::Duration::Locale::it More will be included as time permits/folks volunteer/CLDR becomes an option They are setup this way: DateTime::Format::Human::Duration::Locale::XYZ where 'XYZ' is the ISO code of DateTime::Locale It can have one of 2 functions: =over 4 =item get_human_span_hashref() Takes no arguments, should return a hashref of this structure: sub get_human_span_hashref { return { 'no_oxford_comma' => 1, 'no_time' => 'pas le temps', 'and' => 'et', 'year' => 'an', 'years' => 'ans', 'month' => 'mois', 'months' => 'mois', 'week' => 'semaine', 'weeks' => 'semaines', 'day' => 'jour', 'days' => 'jours', 'hour' => 'heure', 'hours' => 'heures', 'minute' => 'minute', 'minutes' => 'minutes', 'second' => 'seconde', 'seconds' => 'seconds', 'nanosecond' => 'nanoseconde', 'nanoseconds' => 'nanosecondes', }; } =item get_human_span_from_units() Try to use L if the locale allows for it since it's much easier. If you cannot, however, then this will give you the maximum level of configurability. This function receives a hashref of duration values, and a hashref of the L. It should return the localized string. sub get_human_span_from_units { my ($duration_values_hr, $args_hr) = @_; ...; return $string; # 1 year, 2days, 4 hours, and 17 minutes } Please see the example in C. =back =head1 LOCALIZATION of DateTime::Format modules L does an excellent job at implementing localization. Often L based class's either don't support localization or they implement it haphazardly and inconsistently. With this module I hope to model a localization scheme that is inline with L and is consistent and reuseable between based classes. The idea is to determine the locale to use based on a DateTime object. XYZ::Locale should handle looking up (and caching if appropriate) the locale and loading the necessary locale module XYZ::Locale::fr The specific locale module holds the data and possibly logic necessary to do what XYZ does in the vernacular of the given locale. =head2 TODO Eventually the generic logic will be re-broken out into its own module for re-use by your class and I'll have more detailed POD about how to do it. In the meantime if you're interested please contact me and I'd be happy to help and/or expediate this TODO. Also, Dave Rolksy has mentioned to me that this sort of locale data might be appropriate for DateTime::Locale directly from CLDR. If that happens this module will be changed to use that if possible. =head1 FAQ =head2 Why would I want to use this? So you can localize your application's output of time periods without having to do a lot of logic each time you wanted to say it. L has/will have a duration() bracket notation method which prompted this module's existence duration() was prompted by its datetime() brother, all of which uses the most excellent DateTime project! =head2 Why did my duration say '62 seconds' instead of '1 minute and 2 seconds' Because you used an ambiguous duration (one without a base) so there is no way to apply date math and accurately represent the number of each given item in that duration since it may or may not span leap-[second, days, years, etc..] In other words do this (so that your duration can be specifically calculated): $dtb = $dta->clone->add('seconds'=> 62); my $duration = $dta - $dtb; # has a base, its not ambiguous print $span->format_duration($duration); # 1 minutes and 2 seconds not this: my $duration = DateTime::Duration->new('seconds'=> 62); # no base, it is ambiguous print $span->format_duration($duration); # 62 seconds Note L(), does not suffer from this since we're using a specific DateTime object already. print $span->format_duration_between( $dt, $dt->clone()->add('seconds'=> 62) ); # 1 minute and 2 seconds =head2 Why do you put a comma before the 'and' in a group of more than 2 items? We want to use the so-called Oxford comma to avoid ambiguity. =head2 My DateTime::Format::Human::Duration::Locale::XX still outputs in English! That is because it defined neither the L or the L functions It must define one of them or defaults are used. =head2 Why didn't you just use 'DateTime::Format::Duration' Essencially DateTime::Format::Duration is an object representing a single strftime() type string to apply to any given duration. This is not flexible enough for the intent of this module. DateTime::Format::Duration is not a bad module its just for a different purpose than DateTime::Format::Human::Duration =over 4 =item * It was not localizable You either got '2 days' or '1 days' which a) forces it to be in English and b) doesn't even make sense in English. You could get around that by adding logic each time you wanted to call it but that is just messy. =item * Had to keep an item even if it was zero If 'days' was in there you got '0 days', we only want items with a value to show. That'd also require a lot of logic each time you wanted to call which is again messy. =item * This module has no need for reparsing output back into an object Since the datetime info for 2 points in time are generally in a form easily rendered into a DateTime object it'd be silly to even attempt to store and parse the output of this module back into an object. Plus since it all depends on the locale it is in it'd be difficult. =back The purpose of DateTime::Format::Human::Duration was to generate a localized human language description of a duration without the caller needing to supply any logic. =head1 DIAGNOSTICS Throws no warnings or errors of its own =head1 CONFIGURATION AND ENVIRONMENT DateTime::Format::Human::Duration requires no configuration files or environment variables. =head1 DEPENDENCIES None. =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Daniel Muey C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2008, Daniel Muey C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/000755 000765 000024 00000000000 12744215264 030124 5ustar00mstratmanstaff000000 000000 DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale.pm000644 000765 000024 00000006036 12744214540 030463 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale; # require DateTime::Format::Locale; use strict; use warnings; sub calc_locale { my ($span, $loc) = @_; # DateTime::Format::Locale:: my $final = determine_locale_from({ 'base_object' => $span, 'get_locale_from' => $loc, 'locale_ns_path' => 'DateTime/Format/Human/Duration/Locale', # DateTime::Format::Human::Duration::Locale }); if ($final) { return $final if ref $final; # returned 'locale_cache' we created below my $ns = "DateTime::Format::Human::Duration::Locale::$final"; # get_human_span_from_units_array has been deprecated, but we'll # still support it. if ( $ns->can('get_human_span_from_units_array') ) { $span->{'locale_cache'}{ $final } = $ns; } elsif ( $ns->can('get_human_span_from_units') ) { $span->{'locale_cache'}{ $final } = $ns; } elsif ( my $sub = $ns->can('get_human_span_hashref') ) { $span->{'locale_cache'}{ $final } = $sub->(); } if ( exists $span->{'locale_cache'}{ $final } ) { return $span->{'locale_cache'}{ $final }; } } return ''; } # DateTime::Format::Locale:: sub determine_locale_from { my ($args_hr) = @_; return '' if !$args_hr->{'get_locale_from'}; if (ref $args_hr->{'get_locale_from'}) { my $locale_obj; if (UNIVERSAL::can($args_hr->{'get_locale_from'}, 'locale')) { $locale_obj = $args_hr->{'get_locale_from'}->locale; } else { $locale_obj = $args_hr->{'get_locale_from'}; } if (UNIVERSAL::can($locale_obj, 'code')) { $args_hr->{'get_locale_from'} = $locale_obj->code; # DateTime::Locale v1 } elsif (UNIVERSAL::can($locale_obj, 'id')) { $args_hr->{'get_locale_from'} = $locale_obj->id; # DateTime::Locale v0 } else { my $ns = ref($args_hr->{'get_locale_from'}); ($args_hr->{'get_locale_from'}) = reverse split /::/, $ns; } } my ($short) = split(/[-_]+/,$args_hr->{'get_locale_from'}); my $final = ''; my @try = $args_hr->{'get_locale_from'} eq $short ? ($args_hr->{'get_locale_from'}) : ($args_hr->{'get_locale_from'}, $short); NS: for my $locale ( @try ) { if ( exists $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { if ( $args_hr->{'base_object'}{'locale_cache'}{ $locale } ) { return $locale; } else { next NS; } } $args_hr->{'locale_ns_path'} =~ s{/$}{}; my $path = "$args_hr->{'locale_ns_path'}/$locale\.pm"; if( exists $INC{$path} || eval { $args_hr->{'loads'}{$locale}++; require $path } ) { $final = $locale; $args_hr->{'base_object'}{'locale_cache'}{ $locale } = 1; last NS; } else { push @{$args_hr->{'errors'}{$locale}}, $@; $args_hr->{'base_object'}{'locale_cache'}{ $locale } = ''; } } return $final; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/de.pm000644 000765 000024 00000001327 12464635612 031057 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::de; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 0, 'no_time' => 'Keine Zeit', 'and' => 'und', 'year' => 'Jahr', 'years' => 'Jahre', 'month' => 'Monat', 'months' => 'Monate', 'week' => 'Woche', 'weeks' => 'Wochen', 'day' => 'Tag', 'days' => 'Tage', 'hour' => 'Stunde', 'hours' => 'Stunden', 'minute' => 'Minute', 'minutes' => 'Minuten', 'second' => 'Sekunde', 'seconds' => 'Sekunden', 'nanosecond' => 'Nanosekunde', 'nanoseconds' => 'Nanosekunden', }; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/es.pm000644 000765 000024 00000001325 12464635612 031074 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::es; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 0, 'no_time' => 'no hay tiempo', 'and' => 'y', 'year' => 'año', 'years' => 'años', 'month' => 'mes', 'months' => 'meses', 'week' => 'semana', 'weeks' => 'semanas', 'day' => 'día', 'days' => 'días', 'hour' => 'hora', 'hours' => 'horas', 'minute' => 'minuto', 'minutes' => 'minutos', 'second' => 'segundo', 'seconds' => 'segundos', 'nanosecond' => 'nanosegundo', 'nanoseconds' => 'nanosegundos', }; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/fr.pm000644 000765 000024 00000001332 12464635612 031072 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::fr; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 1, 'no_time' => 'pas le temps', 'and' => 'et', 'year' => 'an', 'years' => 'ans', 'month' => 'mois', 'months' => 'mois', 'week' => 'semaine', 'weeks' => 'semaines', 'day' => 'jour', 'days' => 'jours', 'hour' => 'heure', 'hours' => 'heures', 'minute' => 'minute', 'minutes' => 'minutes', 'second' => 'seconde', 'seconds' => 'seconds', 'nanosecond' => 'nanoseconde', 'nanoseconds' => 'nanosecondes', }; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/it.pm000644 000765 000024 00000001321 12464635612 031075 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::it; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 1, 'no_time' => 'zero secondi', 'and' => 'e', 'year' => 'anno', 'years' => 'anni', 'month' => 'mese', 'months' => 'mesi', 'week' => 'settimana', 'weeks' => 'settimane', 'day' => 'giorno', 'days' => 'giorni', 'hour' => 'ora', 'hours' => 'ore', 'minute' => 'minuto', 'minutes' => 'minuti', 'second' => 'secondo', 'seconds' => 'secondi', 'nanosecond' => 'nanosecondo', 'nanoseconds' => 'nanosecondi', }; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/ja.pm000644 000765 000024 00000003626 12464635612 031065 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::ja; use strict; use warnings; sub get_human_span_from_units { my ($duration_units, $args_hr) = @_; my %n = map { ($_ => abs $duration_units->{$_}) } keys %$duration_units; # # もっとよい訳にしてください! m(_ _)m # # 考えてみると日本語って難しい。。。 # とりあえず「前」「後」を付けた場合と、無しの場合で変じゃないように。 # こんなんで悩むとは思わなかったが、日本語使えてない!? # # * 公文書は「一箇月」新聞は「一カ月」だそうです。 # # 採用 # 1年2ヶ月前 # 1年2ヶ月 # 1年2ヶ月3分前 # 1年2ヶ月3分 # 1時間2秒 # 1時間前 # 1週間前 # ググルと 1週間前 より 1週前 のほうが多いが、レースなどか。。。 # 1週間 # # 不採用 # 1ヶ年2ヶ月3分前 # 1年2ヶ月3分間前 # 1年2ヶ月3分間 # 1時間2秒間 # 1週前 # 1週後 # my $s = join "", ( $n{years} ? "$n{years}年" : () ), ( $n{months} ? "$n{months}ヶ月" : () ), ( $n{weeks} ? "$n{weeks}週間" : () ), ( $n{days} ? "$n{days}日" : () ), ( $n{hours} ? "$n{hours}時間" : () ), ( $n{minutes} ? "$n{minutes}分" : () ), ( $n{seconds} ? "$n{seconds}秒" : () ); my $past = grep { $_ < 0 } values %$duration_units; my $say = ''; if ($past && $args_hr->{past}) { $say = $args_hr->{past}; } elsif (! $past && $args_hr->{future}) { $say = $args_hr->{future}; } if ($say) { $s = $say =~ m{%s} ? sprintf($say, $s): "$s$say"; } unless ($s) { $s = $args_hr->{no_time} || "時間なし"; } return $s; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/ko.pm000644 000765 000024 00000001534 12464635612 031100 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::ko; use utf8; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 1, 'no_time' => '시간 없음', 'and' => q{}, 'year' => '년', 'years' => '년', 'month' => '개월', 'months' => '개월', 'week' => '주', 'weeks' => '주', 'day' => '일', 'days' => '일', 'hour' => '시간', 'hours' => '시간', 'minute' => '분', 'minutes' => '분', 'second' => '초', 'seconds' => '초', 'nanosecond' => '나노초', 'nanoseconds' => '나노초', }; } 1; DateTime-Format-Human-Duration-0.64/lib/DateTime/Format/Human/Duration/Locale/pt.pm000644 000765 000024 00000001363 12464635612 031112 0ustar00mstratmanstaff000000 000000 package DateTime::Format::Human::Duration::Locale::pt; use strict; use warnings; sub get_human_span_hashref { return { 'no_oxford_comma' => 0, 'no_time' => 'nenhum momento', 'and' => 'e', 'year' => 'ano', 'years' => 'anos', 'month' => 'mês', 'months' => 'meses', 'week' => 'semana', 'weeks' => 'semanas', 'day' => 'dia', 'days' => 'dias', 'hour' => 'hora', 'hours' => 'horas', 'minute' => 'minuto', 'minutes' => 'minutos', 'second' => 'segundo', 'seconds' => 'segundos', 'nanosecond' => 'nanosegundo', # nanosecond ? 'nanoseconds' => 'nanosegundos', # nanosegundos ? }; } 1;