RT 5.0.2 Documentation

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.

ParseByTimeParseDate

Parse date using Time::ParseDate. return undef if it fails to parse, otherwise return epoch time.

ParseByDateTimeFormatNatural

Parse date using DateTime::Format::Natural. return undef if it fails to parse, otherwise return epoch time.

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.

Takes optional named arguments:

AgeAsString

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

AsString

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

If the current user didn't choose preferred 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

Returns a formatted and localized string that represents the 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 understands 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 date_format_full and time_format_medium), 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-independent, 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-independent and is close enough 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-independent 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-independent and always represented in GMT which 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. If only date requested then user's timezone is used, otherwise it's UTC.

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 make much sense and most probably would produce unexpected results, so the method ignores 'utc' context and uses the offset returned by the "Localtime" method.

Timezone $context

Returns the timezone name for the specified context. $context should be one of these values:

user

The current user's Timezone value will be returned.

server

The value of the Timezone RT config option will be returned.

For any other value of $context, or if the specified context has no defined timezone, UTC is returned.

IsSet

Returns true if this Date is set in the database, otherwise returns a false value.

This avoids needing to compare to 1970-01-01 in any of your code.

DateTimeObj [Timezone => 'utc']

Returns an DateTime object representing the same time as this RT::Date. The DateTime object's locale is set up to match the user's language.

Modifying this DateTime object will not change the corresponding RT::Date, and vice versa.

Strftime FORMAT, [Timezone => 'user']

Stringify the RT::Date according to the specified format. See "strftime Patterns" in DateTime.

← Back to index