greatshots has asked for the wisdom of the Perl Monks concerning the following question:

vanakam monks,

Time::Tiny

my $today = Time::Tiny->now; print "Year : " . $today->year . "\n"; print "Month: " . $today->month . "\n"; print "Day : " . $today->day . "\n";
when I executed the above code, I got the following error
Can't locate object method "year" via package "Time::Tiny" at time_tin +y.pl line 10.
blinking, why it throws that error ?

Replies are listed 'Best First'.
Re: problem in getting tody's date using Time::Tiny module
by ysth (Canon) on Sep 18, 2006 at 07:27 UTC
    It appears you want Date::Tiny instead; part of the pod in Time::Tiny seems to be for Date::Tiny by mistake. Time::Tiny only has time-of-day related fields.
Re: problem in getting tody's date using Time::Tiny module
by davido (Cardinal) on Sep 18, 2006 at 06:56 UTC

    There is either a bug in the documentation for that module, or in the module itself, depending on how you look at it. One thing is sure. There is no Time::Tiny->year() function. There is also no ->month() function, nor a day() function. Seems like fairly significant omissions from the code given the documentation. ;)

    Personally I would move on and use a different module; this one apparently isn't all that well tested/refined. It appears to be seriously flawed.


    Dave

Re: problem in getting tody's date using Time::Tiny module
by davorg (Chancellor) on Sep 18, 2006 at 15:53 UTC

    As others have explained, Time::Tiny is for dealing with times and doesn't contain methods for dealing with dates. The Pod seems to be in error. You might like to annotate the Pod or raise a bug to alert the author of this problem.

    A lot of the date/time stuff that most people want to do can be done in Perl using a combination of time, localtime, Time::Local and strftime (from POSIX.pm). And if those few functions and modules don't do what you want, I'd look at the DateTime set of modules rather than any of the many other random date and time modules that you find on CPAN.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: problem in getting tody's date using Time::Tiny module
by mikasue (Friar) on Sep 18, 2006 at 15:42 UTC
    I personally like Date::Calc. I dont' know what the purpose of your entire program is but if you need more Date functions look into it.