[BACK]Return to Util.pm CVS log [TXT][DIR] Up to [local] / RT / Invoicing / lib / RTI

File: [local] / RT / Invoicing / lib / RTI / Util.pm (download)

Revision 1.2, Sat Dec 31 02:21:09 2011 UTC (12 years, 5 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +9 -1 lines

Add round

package RTI::Util;
use strict;
use warnings;

use base 'Exporter';
use 5.010;
use Carp;
use DateTime;

our @EXPORT_OK = qw/ round ymd_to_DateTime /;

sub round {
    my ($amount) = @_;

    #$amount =~ s/\.\d\d\K.*$//;
    #return $amount;
    return sprintf "%.02f", $amount;
}

sub ymd_to_DateTime {
    my ($ymd) = @_;

    return unless $ymd;

    my ( $date, $time ) = split /[\sT]/, $ymd;
    my ( $year, $month, $day ) = split '-', $date;
    my ( $hour, $minute, $second ) = split ':', $time if $time;

    return DateTime->new(
        year      => $year,
        month     => $month,
        day       => $day,
        hour      => $hour || 0,
        minute    => $minute || 0,
        second    => $second || 0,
        time_zone => 'local',
    );
}