autobox::Numeric::Time - ActiveSupport equivalent to Perl numeric variables


autobox-Numeric-Time documentation Contained in the autobox-Numeric-Time distribution.

Index


Code Index:

NAME

Top

autobox::Numeric::Time - ActiveSupport equivalent to Perl numeric variables

SYNOPSIS

Top

    use autobox;
    use autobox::Numeric::Time;

    print 2->seconds; # 2
    print 3->minutes; # 180
    print 3->hours;   # 10800
    print 2->days;    # 172800

DESCRIPTION

Top

autobox::Numeric::Time is an autobox module to add Time-related methods to core integer values by using constant overloading. Inspired by ActiveSupport (Rails) Core extensions to Numeric values and autobox::DateTime::Duration.

METHODS

Top

seconds, second
minutes, minute
hours, hour
days, day
weeks, week
fortnights, fortnight
months, month
years, year

CAVEATS

Top

This module does not support following methods:

  ago
  until
  since
  from_now

if you need, try to use autobox::DateTime::Duration.

SEE ALSO

Top

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html

autobox, autobox::DateTime::Duration

AUTHOR

Top

HIROSE Masaaki, <hirose31@gmail.com>

BUGS

Top

Please report any bugs or feature requests to bug-autobox-numeric-time@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


autobox-Numeric-Time documentation Contained in the autobox-Numeric-Time distribution.

package autobox::Numeric::Time;

use strict;
use warnings;
use Carp;

use base qw(autobox);

our $VERSION = '0.02';

sub import {
    shift->SUPER::import(NUMBER => 'autobox::Numeric::Time::Impl', @_);
}

package # hide from pause
    autobox::Numeric::Time::Impl;

sub seconds {
    return $_[0];
}
*second = \&seconds;

sub minutes {
    return $_[0] * 60;
}
*minute = \&minutes;

sub hours {
    return $_[0] * 3600;
}
*hour = \&hours;

sub days {
    return $_[0] * 3600 * 24;
}
*day = \&days;

sub weeks {
    return $_[0] * 3600 * 24 * 7;
}
*week = \&weeks;

sub fortnights {
    return $_[0] * 3600 * 24 * 7 * 2;
}
*fortnight = \&fortnights;

sub months {
    return $_[0] * 3600 * 24 * 30;
}
*month = \&months;

sub years {
    return $_[0] * 3600 * 24 * 365.25;
}
*year = \&years;

1;

__END__