NAME
Weather::Com::DateTime - date and time class
SYNOPSIS
#!/usr/bin/perl -w
use Weather::Com::DateTime;
my $now = time();
my $datetime = Weather::Com::DateTime->new($now);
print "Today it's the ", $datetime->date(), "\n";
print "and it's currently ", $datetime->time(), "o'clock.\n";
DESCRIPTION
Weather::Com::DateTime objects are used to encapsulate a date or time provided by the OO interface (e.g. localtime, sunrise, sunset, etc.).
This is done because there are many ways to use a date or time and to present it in your programs using Weather::Com. This class provides some predefined formats for date and time but also enables you to easily define your own ones.
There are two ways to get your own date or time format:
You use the
formatted()
method and provide a format string to it.If you'd like to define your own
date()
ortime()
method, simply change the corresponding methods.What you can change in which way without destroying the whole class, is described in section INTERFACE.
CONSTRUCTOR
You usually would not construct an object of this class yourself. This is implicitely done when you call one of the OO interfaces date or time methods.
The constructor can take a time in epoc seconds.
INTERFACE
This class can simply be customized to fit your personal needs.
If you have your own special date and time formats you always want to use in your programm, simply change the default ones.
If you sometimes need another format than usual, use the formatted()
method instead, providing a date or time format string to it, corresponding to the Time::Format module.
The following methods should not be removed because they make up the interface of the class as used by the rest of Weather::Com:
set_date()
set_time()
set_lsup()
date()
time()
time_ampm()
All these methods are needed by the other classes.
Please do not touch the setter methods and the 'ampm' method.
The methods date()
and time()
can be adjusted by you to fit your date and time format wishes, as long as they return anything.
METHODS
epoc(epoc seconds)
With this method you can set the date and time using epocs directly.
It returns the currently set epoc seconds.
formatted(format)
This method returns a date or time formatted in the way you ask for.
The format
you provide to this method has to be a valid Time::Format format. For details please refer to Time::Format.
set_date(date)
With this method one can set the date of the object using an input format like Feb 13
which is the 13th of february of the current year.
Using this method, the time is set to 00:00. The year is the current one.
set_time(time)
With this method one can set the time of the object using an input format like 8:30 AM
.
The date is set to the current date of the host the script is running on.
set_lsup(lsup)
With this method one can set the date of the object using the weather.com's special last update format that is like 2/12/05 4:50 PM Local Time
.
date()
Returns the date in the format 1. February 2005
.
time()
Returns the time in the format 22:15
.
time_ampm()
Returns the time in the format 10:15 PM
.
weekday()
Returns the day of week with like Wednesday
.
day()
Returns the day in month.
month()
Returns the name of the month.
mon()
Returns the number of the month
year()
Returns the year (4 digits).
AUTHOR
Thomas Schnuecker, <thomas@schnuecker.de>
COPYRIGHT AND LICENSE
Copyright (C) 2004-2005 by Thomas Schnuecker
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The data provided by weather.com and made accessible by this OO interface can be used for free under special terms. Please have a look at the application programming guide of weather.com (http://www.weather.com/services/xmloap.html)!