RT 4.0.24 Documentation

This version has reached its end of life and is out of support. Please contact us for upgrade assistance.

RT::Date

Go to latest version →

NAME

  RT::Date - a simple Object Oriented date.

SYNOPSIS

  use RT::Date

DESCRIPTION

RT Date is a simple Date Object designed to be speedy and easy for RT to use

The fact that it assumes that a time of 0 means "never" is probably a bug.

METHODS

new

Object constructor takes one argument RT::CurrentUser object.

Set

Takes a param hash with the fields Format, Value and Timezone.

If $args->{'Format'} is 'unix', takes the number of seconds since the epoch.

If $args->{'Format'} is ISO, tries to parse an ISO date.

If $args->{'Format'} is 'unknown', require Time::ParseDate and make it figure things out. This is a heavyweight operation that should never be called from within RT's core. But it's really useful for something like the textbox date entry where we let the user do whatever they want.

If $args->{'Value'} is 0, assumes you mean never.

SetToNow

Set the object's time to the current time. Takes no arguments and returns unix time.

SetToMidnight [Timezone => 'utc']

Sets the date to midnight (at the beginning of the day). Returns the unixtime at midnight.

Arguments:

Timezone

Timezone context user, server or UTC. See also "Timezone".

Diff

Takes either an RT::Date object or the date in unixtime format as a string, if nothing is specified uses the current time.

Returns the differnce between the time in the current object and that time as a number of seconds. Returns undef if any of two compared values is incorrect or not set.

DiffAsString

Takes either an RT::Date object or the date in unixtime format as a string, if nothing is specified uses the current time.

Returns the differnce between $self and that time as a number of seconds as a localized string fit for human consumption. Returns empty string if any of two compared values is incorrect or not set.

DurationAsString

Takes a number of seconds. Returns a localized string describing that duration.

AgeAsString

Takes nothing. Returns a string that's the differnce between the time in the object and now.

AsString

Returns the object's time as a localized string with curent user's prefered format and timezone.

If the current user didn't choose prefered format then system wide setting is used or "DefaultFormat" if the latter is not specified. See config option DateTimeFormat.

GetWeekday DAY

Takes an integer day of week and returns a localized string for that day of week. Valid values are from range 0-6, Note that 0 is sunday.

GetMonth MONTH

Takes an integer month and returns a localized string for that month. Valid values are from from range 0-11.

AddSeconds SECONDS

Takes a number of seconds and returns the new unix time.

Negative value can be used to substract seconds.

AddDays [DAYS]

Adds 24 hours * DAYS to the current time. Adds one day when no argument is specified. Negative value can be used to substract days.

Returns new unix time.

AddDay

Adds 24 hours to the current time. Returns new unix time.

Unix [unixtime]

Optionally takes a date in unix seconds since the epoch format. Returns the number of seconds since the epoch

DateTime

Alias for "Get" method. Arguments Date and <Time> are fixed to true values, other arguments could be used as described in "Get".

Date

Takes Format argument which allows you choose date formatter. Pass throught other arguments to the formatter method.

Returns the object's formatted date. Default formatter is ISO.

Time

Get

Returnsa a formatted and localized string that represets time of the current object.

Output formatters

Fomatter is a method that returns date and time in different configurable format.

Each method takes several arguments:

Date
Time
Timezone - Timezone context server, user or UTC

Formatters may also add own arguments to the list, for example in RFC2822 format day of time in output is optional so it understand boolean argument DayOfTime.

Formatters

Returns an array of available formatters.

ValidFormatter FORMAT

Returns a true value if FORMAT is a known formatter. Otherwise returns false.

DefaultFormat

LocaleObj

Returns the DateTime::Locale object representing the current user's locale.

LocalizedDateTime

Returns date and time as string, with user localization.

Supports arguments: DateFormat and TimeFormat which may contains date and time format as specified in DateTime::Locale (default to full_date_format and medium_time_format), AbbrDay and AbbrMonth which may be set to 0 if you want full Day/Month names instead of abbreviated ones.

ISO

Returns the object's date in ISO format YYYY-MM-DD mm:hh:ss. ISO format is locale independant, but adding timezone offset info is not implemented yet.

Supports arguments: Timezone, Date, Time and Seconds. See </Output formatters> for description of arguments.

W3CDTF

Returns the object's date and time in W3C date time format (http://www.w3.org/TR/NOTE-datetime).

Format is locale independand and is close enought to ISO, but note that date part is not optional and output string has timezone offset mark in [+-]hh:mm format.

Supports arguments: Timezone, Time and Seconds. See </Output formatters> for description of arguments.

RFC2822 (MIME)

Returns the object's date and time in RFC2822 format, for example Sun, 06 Nov 1994 08:49:37 +0000. Format is locale independand as required by RFC. Time part always has timezone offset in digits with sign prefix.

Supports arguments: Timezone, Date, Time, DayOfWeek and Seconds. See </Output formatters> for description of arguments.

RFC2616 (HTTP)

Returns the object's date and time in RFC2616 (HTTP/1.1) format, for example Sun, 06 Nov 1994 08:49:37 GMT. While the RFC describes version 1.1 of HTTP, but the same form date can be used in version 1.0.

Format is fixed length, locale independand and always represented in GMT what makes it quite useless for users, but any date in HTTP transfers must be presented using this format.

    HTTP-date = rfc1123 | ...
    rfc1123   = wkday "," SP date SP time SP "GMT"
    date      = 2DIGIT SP month SP 4DIGIT
                ; day month year (e.g., 02 Jun 1982)
    time      = 2DIGIT ":" 2DIGIT ":" 2DIGIT
                ; 00:00:00 - 23:59:59
    wkday     = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun"
    month     = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun"
              | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"

Supports arguments: Date and Time, but you should use them only for some personal reasons, RFC2616 doesn't define any optional parts. See </Output formatters> for description of arguments.

iCal

Returns the object's date and time in iCalendar format,

Supports arguments: Date and Time. See </Output formatters> for description of arguments.

Timezones handling

Localtime $context [$time]

Takes one mandatory argument $context, which determines whether we want "user local", "system" or "UTC" time. Also, takes optional argument unix $time, default value is the current unix time.

Returns object's date and time in the format provided by perl's builtin functions localtime and gmtime with two exceptions:

1) "Year" is a four-digit year, rather than "years since 1900"

2) The last element of the array returned is offset, which represents timezone offset against UTC in seconds.

Timelocal $context @time

Takes argument $context, which determines whether we should treat @time as "user local", "system" or "UTC" time.

@time is array returned by Localtime functions. Only first six elements are mandatory - $sec, $min, $hour, $mday, $mon and $year. You may pass $wday, $yday and $isdst, these are ignored.

If you pass $offset as ninth argument, it's used instead of $context. It's done such way as code $self-Timelocal('utc', $self->Localtime('server'))> doesn't makes much sense and most probably would produce unexpected result, so the method ignore 'utc' context and uses offset returned by Localtime method.

Timezone $context

Returns the timezone name.

Takes one argument, $context argument which could be user, server or utc.

user

Default value is user that mean it returns current user's Timezone value.

server

If context is server it returns value of the Timezone RT config option.

utc

If both server's and user's timezone names are undefined returns 'UTC'.

← Back to index