On Feb 13, 2012, at 2:22 PM, Daniel Muey via RT wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=74923 >
>
> On Mon Feb 13 07:09:14 2012, ANDREMAR wrote:
>> I'm trying to write a (admittedly hackish) locale, in which I want to
>> use
>> get_human_span_from_units_array, since I need to only show some
>> values.
>>
>> The problem is that in that function I have no idea if the duration is
>> positive or negative, as the
>> $say variable is not passed along.
>
> It sounds like get_human_span_from_units_array() is doing to much, maybe not though, can
> you send a simple completye example of the problem?
>
> thanks
>
>
package DateTime::Format::Human::Duration::Locale::nb;
# XXX: this isn't really NB locale, I just cheat the system.
#
use strict;
use warnings;
use Data::Dump;
sub get_human_span_from_units_array {
my ($years, $months, $weeks, $days, $hours, $minutes, $seconds, $nanoseconds, $args_hr) = @_; # note: has no negative numbers
my $s = '';
if ($years) {
$s = $years . "y";
} elsif ($months) {
$s = $months . "mo";
} elsif ($weeks) {
$s = $weeks . "w";
} elsif ($days) {
$s = $days . "d";
} elsif ($hours) {
$s = $hours . "h";
} elsif ($minutes) {
$s = $minutes . "mi";
} elsif ($seconds) {
$s = "moments";
}
return sprintf($args_hr->{past}, $s);
}
1;
Since the string returned from get_human_span_from_units_array is returned verbatim, without getting sprinted into $say (in
https://metacpan.org/source/DMUEY/DateTime-Format-Human-Duration-0.0.1/lib/DateTime/Format/Human/Duration.pm#L80), I just have to use $args_hr->{past} since I know they will be in the past.
I realize that this is not the intended use of this module, so if you just want to disregard, feel free, but if I had a legitimate need to use get_human_span_from_units_array, I would imagine it would need to know in what direction the span is, or at the very least get feeded back into the past/future strings from the calling method.