1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
51 RT::Date - a simple Object Oriented date.
59 RT Date is a simple Date Object designed to be speedy and easy for RT to use
61 The fact that it assumes that a time of 0 means "never" is probably a bug.
76 use base qw/RT::Base/;
78 use vars qw($MINUTE $HOUR $DAY $WEEK $MONTH $YEAR);
84 $MONTH = 30.4375 * $DAY;
85 $YEAR = 365.25 * $DAY;
102 our @DAYS_OF_WEEK = (
113 'DefaultFormat', # loc
120 if ( eval 'use DateTime qw(); 1;' && eval 'use DateTime::Locale qw(); 1;' &&
121 DateTime->can('format_cldr') && DateTime::Locale::root->can('date_format_full') ) {
122 push @FORMATTERS, 'LocalizedDateTime'; # loc
127 Object constructor takes one argument C<RT::CurrentUser> object.
133 my $class = ref($proto) || $proto;
135 bless ($self, $class);
136 $self->CurrentUser(@_);
143 Takes a param hash with the fields C<Format>, C<Value> and C<Timezone>.
145 If $args->{'Format'} is 'unix', takes the number of seconds since the epoch.
147 If $args->{'Format'} is ISO, tries to parse an ISO date.
149 If $args->{'Format'} is 'unknown', require Time::ParseDate and make it figure
150 things out. This is a heavyweight operation that should never be called from
151 within RT's core. But it's really useful for something like the textbox date
152 entry where we let the user do whatever they want.
154 If $args->{'Value'} is 0, assumes you mean never.
167 return $self->Unix(0) unless $args{'Value'};
169 if ( $args{'Format'} =~ /^unix$/i ) {
170 return $self->Unix( $args{'Value'} );
172 elsif ( $args{'Format'} =~ /^(sql|datemanip|iso)$/i ) {
173 $args{'Value'} =~ s!/!-!g;
175 if ( ( $args{'Value'} =~ /^(\d{4})?(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ )
176 || ( $args{'Value'} =~ /^(\d{4})?(\d\d)(\d\d)(\d\d):(\d\d):(\d\d)$/ )
177 || ( $args{'Value'} =~ /^(?:(\d{4})-)?(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/ )
178 || ( $args{'Value'} =~ /^(?:(\d{4})-)?(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\+00$/ )
181 my ($year, $mon, $mday, $hours, $min, $sec) = ($1, $2, $3, $4, $5, $6);
183 # use current year if string has no value
184 $year ||= (localtime time)[5] + 1900;
186 #timegm expects month as 0->11
189 #now that we've parsed it, deal with the case where everything was 0
190 return $self->Unix(0) if $mon < 0 || $mon > 11;
192 my $tz = lc $args{'Format'} eq 'datemanip'? 'user': 'utc';
193 $self->Unix( $self->Timelocal( $tz, $sec, $min, $hours, $mday, $mon, $year ) );
195 $self->Unix(0) unless $self->Unix > 0;
198 $RT::Logger->warning(
199 "Couldn't parse date '$args{'Value'}' as a $args{'Format'} format"
201 return $self->Unix(0);
204 elsif ( $args{'Format'} =~ /^unknown$/i ) {
205 require Time::ParseDate;
206 # the module supports only legacy timezones like PDT or EST...
207 # so we parse date as GMT and later apply offset, this only
208 # should be applied to absolute times, so compensate shift in NOW
210 $now += ($self->Localtime( $args{Timezone}, $now ))[9];
211 my $date = Time::ParseDate::parsedate(
215 UK => RT->Config->Get('DateDayBeforeMonth'),
216 PREFER_PAST => RT->Config->Get('AmbiguousDayInPast'),
217 PREFER_FUTURE => RT->Config->Get('AmbiguousDayInFuture'),
219 # apply timezone offset
220 $date -= ($self->Localtime( $args{Timezone}, $date ))[9];
223 "RT::Date used Time::ParseDate to make '$args{'Value'}' $date\n"
226 return $self->Set( Format => 'unix', Value => $date);
230 "Unknown Date format: $args{'Format'}\n"
232 return $self->Unix(0);
240 Set the object's time to the current time. Takes no arguments
241 and returns unix time.
246 return $_[0]->Unix(time);
249 =head2 SetToMidnight [Timezone => 'utc']
251 Sets the date to midnight (at the beginning of the day).
252 Returns the unixtime at midnight.
260 Timezone context C<user>, C<server> or C<UTC>. See also L</Timezone>.
268 my %args = ( Timezone => '', @_ );
269 my $new = $self->Timelocal(
271 0,0,0,($self->Localtime( $args{'Timezone'} ))[3..9]
273 return $self->Unix( $new );
276 =head2 SetToStart PERIOD[, Timezone => 'utc' ]
278 Set to the beginning of the current PERIOD, which can be
279 "year", "month", "day", "hour", or "minute".
287 my $tz = $args{'Timezone'} || '';
288 my @localtime = $self->Localtime($tz);
290 # This is the cleanest way to implement it, I swear.
293 last if ($p eq 'MINUTE');
295 last if ($p eq 'HOUR');
297 last if ($p eq 'DAY');
299 last if ($p eq 'MONTH');
301 last if ($p eq 'YEAR');
302 $RT::Logger->warning("Couldn't find start date of '$p'.");
305 my $new = $self->Timelocal($tz, @localtime);
306 return $self->Unix($new);
311 Takes either an C<RT::Date> object or the date in unixtime format as a string,
312 if nothing is specified uses the current time.
314 Returns the differnce between the time in the current object and that time
315 as a number of seconds. Returns C<undef> if any of two compared values is
316 incorrect or not set.
323 $other = time unless defined $other;
324 if ( UNIVERSAL::isa( $other, 'RT::Date' ) ) {
325 $other = $other->Unix;
327 return undef unless $other=~ /^\d+$/ && $other > 0;
329 my $unix = $self->Unix;
330 return undef unless $unix > 0;
332 return $unix - $other;
337 Takes either an C<RT::Date> object or the date in unixtime format as a string,
338 if nothing is specified uses the current time.
340 Returns the differnce between C<$self> and that time as a number of seconds as
341 a localized string fit for human consumption. Returns empty string if any of
342 two compared values is incorrect or not set.
348 my $diff = $self->Diff( @_ );
349 return '' unless defined $diff;
351 return $self->DurationAsString( $diff );
354 =head2 DurationAsString
356 Takes a number of seconds. Returns a localized string describing
361 sub DurationAsString {
363 my $duration = int shift;
365 my ( $negative, $s, $time_unit );
366 $negative = 1 if $duration < 0;
367 $duration = abs $duration;
369 if ( $duration < $MINUTE ) {
371 $time_unit = $self->loc("sec");
373 elsif ( $duration < ( 2 * $HOUR ) ) {
374 $s = int( $duration / $MINUTE + 0.5 );
375 $time_unit = $self->loc("min");
377 elsif ( $duration < ( 2 * $DAY ) ) {
378 $s = int( $duration / $HOUR + 0.5 );
379 $time_unit = $self->loc("hours");
381 elsif ( $duration < ( 2 * $WEEK ) ) {
382 $s = int( $duration / $DAY + 0.5 );
383 $time_unit = $self->loc("days");
385 elsif ( $duration < ( 2 * $MONTH ) ) {
386 $s = int( $duration / $WEEK + 0.5 );
387 $time_unit = $self->loc("weeks");
389 elsif ( $duration < $YEAR ) {
390 $s = int( $duration / $MONTH + 0.5 );
391 $time_unit = $self->loc("months");
394 $s = int( $duration / $YEAR + 0.5 );
395 $time_unit = $self->loc("years");
399 return $self->loc( "[_1] [_2] ago", $s, $time_unit );
402 return $self->loc( "[_1] [_2]", $s, $time_unit );
408 Takes nothing. Returns a string that's the differnce between the
409 time in the object and now.
413 sub AgeAsString { return $_[0]->DiffAsString }
419 Returns the object's time as a localized string with curent user's prefered
422 If the current user didn't choose prefered format then system wide setting is
423 used or L</DefaultFormat> if the latter is not specified. See config option
432 return $self->loc("Not set") unless $self->Unix > 0;
434 my $format = RT->Config->Get( 'DateTimeFormat', $self->CurrentUser ) || 'DefaultFormat';
435 $format = { Format => $format } unless ref $format;
436 %args = (%$format, %args);
438 return $self->Get( Timezone => 'user', %args );
441 =head2 GetWeekday DAY
443 Takes an integer day of week and returns a localized string for
444 that day of week. Valid values are from range 0-6, Note that B<0
453 return $self->loc($DAYS_OF_WEEK[$dow])
454 if $DAYS_OF_WEEK[$dow];
458 =head2 GetMonth MONTH
460 Takes an integer month and returns a localized string for that month.
461 Valid values are from from range 0-11.
469 return $self->loc($MONTHS[$mon])
474 =head2 AddSeconds SECONDS
476 Takes a number of seconds and returns the new unix time.
478 Negative value can be used to substract seconds.
484 my $delta = shift or return $self->Unix;
486 $self->Set(Format => 'unix', Value => ($self->Unix + $delta));
488 return ($self->Unix);
491 =head2 AddDays [DAYS]
493 Adds C<24 hours * DAYS> to the current time. Adds one day when
494 no argument is specified. Negative value can be used to substract
497 Returns new unix time.
503 my $days = shift || 1;
504 return $self->AddSeconds( $days * $DAY );
509 Adds 24 hours to the current time. Returns new unix time.
513 sub AddDay { return $_[0]->AddSeconds($DAY) }
517 Adds one month to the current time. Returns new
523 require Time::ParseDate;
526 Time::ParseDate::parsedate(
531 return $self->Unix($date);
534 =head2 Unix [unixtime]
536 Optionally takes a date in unix seconds since the epoch format.
537 Returns the number of seconds since the epoch
543 $self->{'time'} = int(shift || 0) if @_;
544 return $self->{'time'};
549 Alias for L</Get> method. Arguments C<Date> and <Time>
550 are fixed to true values, other arguments could be used
551 as described in L</Get>.
557 unless (defined $self) {
558 use Carp; Carp::confess("undefined $self");
560 return $self->Get( @_, Date => 1, Time => 1 );
565 Takes Format argument which allows you choose date formatter.
566 Pass throught other arguments to the formatter method.
568 Returns the object's formatted date. Default formatter is ISO.
574 return $self->Get( @_, Date => 1, Time => 0 );
584 return $self->Get( @_, Date => 0, Time => 1 );
589 Returnsa a formatted and localized string that represets time of
598 my %args = (Format => 'ISO', @_);
599 my $formatter = $args{'Format'};
600 $formatter = 'ISO' unless $self->can($formatter);
601 return $self->$formatter( %args );
604 =head2 Output formatters
606 Fomatter is a method that returns date and time in different configurable
609 Each method takes several arguments:
617 =item Timezone - Timezone context C<server>, C<user> or C<UTC>
621 Formatters may also add own arguments to the list, for example
622 in RFC2822 format day of time in output is optional so it
623 understand boolean argument C<DayOfTime>.
627 Returns an array of available formatters.
645 my %args = ( Date => 1,
652 # 0 1 2 3 4 5 6 7 8 9
653 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
654 $self->Localtime($args{'Timezone'});
655 $wday = $self->GetWeekday($wday);
656 $mon = $self->GetMonth($mon);
657 ($mday, $hour, $min, $sec) = map { sprintf "%02d", $_ } ($mday, $hour, $min, $sec);
659 if( $args{'Date'} && !$args{'Time'} ) {
660 return $self->loc('[_1] [_2] [_3] [_4]',
661 $wday,$mon,$mday,$year);
662 } elsif( !$args{'Date'} && $args{'Time'} ) {
663 if( $args{'Seconds'} ) {
664 return $self->loc('[_1]:[_2]:[_3]',
667 return $self->loc('[_1]:[_2]',
671 if( $args{'Seconds'} ) {
672 return $self->loc('[_1] [_2] [_3] [_4]:[_5]:[_6] [_7]',
673 $wday,$mon,$mday,$hour,$min,$sec,$year);
675 return $self->loc('[_1] [_2] [_3] [_4]:[_5] [_6]',
676 $wday,$mon,$mday,$hour,$min,$year);
681 =head3 LocalizedDateTime
683 Returns date and time as string, with user localization.
685 Supports arguments: C<DateFormat> and C<TimeFormat> which may contains date and
686 time format as specified in DateTime::Locale (default to full_date_format and
687 medium_time_format), C<AbbrDay> and C<AbbrMonth> which may be set to 0 if
688 you want full Day/Month names instead of abbreviated ones.
690 Require optionnal DateTime::Locale module.
694 sub LocalizedDateTime
697 my %args = ( Date => 1,
700 DateFormat => 'date_format_full',
701 TimeFormat => 'time_format_medium',
707 return $self->loc("DateTime module missing") unless ( eval 'use DateTime qw(); 1;' );
708 return $self->loc("DateTime::Locale module missing") unless ( eval 'use DateTime::Locale qw(); 1;' );
709 return $self->loc("DateTime doesn't support format_cldr, you must upgrade to use this feature")
710 unless can DateTime::('format_cldr');
713 my $date_format = $args{'DateFormat'};
714 my $time_format = $args{'TimeFormat'};
716 my $lang = $self->CurrentUser->UserObj->Lang;
718 require I18N::LangTags::Detect;
719 $lang = ( I18N::LangTags::Detect::detect(), 'en' )[0];
723 my $formatter = DateTime::Locale->load($lang);
724 return $self->loc("DateTime::Locale doesn't support date_format_full, you must upgrade to use this feature")
725 unless $formatter->can('date_format_full');
726 $date_format = $formatter->$date_format;
727 $time_format = $formatter->$time_format;
728 $date_format =~ s/EEEE/EEE/g if ( $args{'AbbrDay'} );
729 $date_format =~ s/MMMM/MMM/g if ( $args{'AbbrMonth'} );
731 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
732 $self->Localtime($args{'Timezone'});
734 my $tz = $self->Timezone($args{'Timezone'});
736 # FIXME : another way to call this module without conflict with local
738 my $dt = new DateTime::( locale => $lang,
749 if ( $args{'Date'} && !$args{'Time'} ) {
750 return $dt->format_cldr($date_format);
751 } elsif ( !$args{'Date'} && $args{'Time'} ) {
752 return $dt->format_cldr($time_format);
754 return $dt->format_cldr($date_format) . " " . $dt->format_cldr($time_format);
760 Returns the object's date in ISO format C<YYYY-MM-DD mm:hh:ss>.
761 ISO format is locale independant, but adding timezone offset info
762 is not implemented yet.
764 Supports arguments: C<Timezone>, C<Date>, C<Time> and C<Seconds>.
765 See </Output formatters> for description of arguments.
771 my %args = ( Date => 1,
777 # 0 1 2 3 4 5 6 7 8 9
778 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
779 $self->Localtime($args{'Timezone'});
781 #the month needs incrementing, as gmtime returns 0-11
785 $res .= sprintf("%04d-%02d-%02d", $year, $mon, $mday) if $args{'Date'};
786 $res .= sprintf(' %02d:%02d', $hour, $min) if $args{'Time'};
787 $res .= sprintf(':%02d', $sec, $min) if $args{'Time'} && $args{'Seconds'};
795 Returns the object's date and time in W3C date time format
796 (L<http://www.w3.org/TR/NOTE-datetime>).
798 Format is locale independand and is close enought to ISO, but
799 note that date part is B<not optional> and output string
800 has timezone offset mark in C<[+-]hh:mm> format.
802 Supports arguments: C<Timezone>, C<Time> and C<Seconds>.
803 See </Output formatters> for description of arguments.
816 # 0 1 2 3 4 5 6 7 8 9
817 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
818 $self->Localtime( $args{'Timezone'} );
820 #the month needs incrementing, as gmtime returns 0-11
824 $res .= sprintf("%04d-%02d-%02d", $year, $mon, $mday);
825 if ( $args{'Time'} ) {
826 $res .= sprintf('T%02d:%02d', $hour, $min);
827 $res .= sprintf(':%02d', $sec, $min) if $args{'Seconds'};
829 $res .= sprintf "%s%02d:%02d", $self->_SplitOffset( $offset );
839 =head3 RFC2822 (MIME)
841 Returns the object's date and time in RFC2822 format,
842 for example C<Sun, 06 Nov 1994 08:49:37 +0000>.
843 Format is locale independand as required by RFC. Time
844 part always has timezone offset in digits with sign prefix.
846 Supports arguments: C<Timezone>, C<Date>, C<Time>, C<DayOfWeek>
847 and C<Seconds>. See </Output formatters> for description of
854 my %args = ( Date => 1,
862 # 0 1 2 3 4 5 6 7 8 9
863 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
864 $self->Localtime($args{'Timezone'});
866 my ($date, $time) = ('','');
867 $date .= "$DAYS_OF_WEEK[$wday], " if $args{'DayOfWeek'} && $args{'Date'};
868 $date .= "$mday $MONTHS[$mon] $year" if $args{'Date'};
870 if ( $args{'Time'} ) {
871 $time .= sprintf("%02d:%02d", $hour, $min);
872 $time .= sprintf(":%02d", $sec) if $args{'Seconds'};
873 $time .= sprintf " %s%02d%02d", $self->_SplitOffset( $offset );
876 return join ' ', grep $_, ($date, $time);
879 =head3 RFC2616 (HTTP)
881 Returns the object's date and time in RFC2616 (HTTP/1.1) format,
882 for example C<Sun, 06 Nov 1994 08:49:37 GMT>. While the RFC describes
883 version 1.1 of HTTP, but the same form date can be used in version 1.0.
885 Format is fixed length, locale independand and always represented in GMT
886 what makes it quite useless for users, but any date in HTTP transfers
887 must be presented using this format.
889 HTTP-date = rfc1123 | ...
890 rfc1123 = wkday "," SP date SP time SP "GMT"
891 date = 2DIGIT SP month SP 4DIGIT
892 ; day month year (e.g., 02 Jun 1982)
893 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
894 ; 00:00:00 - 23:59:59
895 wkday = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun"
896 month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun"
897 | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
899 Supports arguments: C<Date> and C<Time>, but you should use them only for
900 some personal reasons, RFC2616 doesn't define any optional parts.
901 See </Output formatters> for description of arguments.
907 my %args = ( Date => 1, Time => 1,
910 Seconds => 1, DayOfWeek => 1,
913 my $res = $self->RFC2822( @_ );
914 $res =~ s/\s*[+-]\d\d\d\d$/ GMT/ if $args{'Time'};
920 Returns the object's date and time in iCalendar format,
922 Supports arguments: C<Date> and C<Time>.
923 See </Output formatters> for description of arguments.
930 Date => 1, Time => 1,
933 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
934 $self->Localtime( 'utc' );
936 #the month needs incrementing, as gmtime returns 0-11
940 if ( $args{'Date'} && !$args{'Time'} ) {
941 $res = sprintf( '%04d%02d%02d', $year, $mon, $mday );
943 elsif ( !$args{'Date'} && $args{'Time'} ) {
944 $res = sprintf( 'T%02d%02d%02dZ', $hour, $min, $sec );
947 $res = sprintf( '%04d%02d%02dT%02d%02d%02dZ', $year, $mon, $mday, $hour, $min, $sec );
952 # it's been added by mistake in 3.8.0
953 sub iCalDate { return (shift)->iCal( Time => 0, @_ ) }
956 my ($self, $offset) = @_;
957 my $sign = $offset < 0? '-': '+';
958 $offset = int( (abs $offset) / 60 + 0.001 );
959 my $mins = $offset % 60;
960 my $hours = int( $offset/60 + 0.001 );
961 return $sign, $hours, $mins;
964 =head2 Timezones handling
966 =head3 Localtime $context [$time]
968 Takes one mandatory argument C<$context>, which determines whether
969 we want "user local", "system" or "UTC" time. Also, takes optional
970 argument unix C<$time>, default value is the current unix time.
972 Returns object's date and time in the format provided by perl's
973 builtin functions C<localtime> and C<gmtime> with two exceptions:
975 1) "Year" is a four-digit year, rather than "years since 1900"
977 2) The last element of the array returned is C<offset>, which
978 represents timezone offset against C<UTC> in seconds.
985 my $tz = $self->Timezone(shift);
987 my $unix = shift || $self->Unix;
988 $unix = 0 unless $unix >= 0;
992 @local = gmtime($unix);
995 local $ENV{'TZ'} = $tz;
996 ## Using POSIX::tzset fixes a bug where the TZ environment variable
999 @local = localtime($unix);
1001 POSIX::tzset(); # return back previouse value
1003 $local[5] += 1900; # change year to 4+ digits format
1004 my $offset = Time::Local::timegm_nocheck(@local) - $unix;
1005 return @local, $offset;
1008 =head3 Timelocal $context @time
1010 Takes argument C<$context>, which determines whether we should
1011 treat C<@time> as "user local", "system" or "UTC" time.
1013 C<@time> is array returned by L<Localtime> functions. Only first
1014 six elements are mandatory - $sec, $min, $hour, $mday, $mon and $year.
1015 You may pass $wday, $yday and $isdst, these are ignored.
1017 If you pass C<$offset> as ninth argument, it's used instead of
1018 C<$context>. It's done such way as code
1019 C<$self->Timelocal('utc', $self->Localtime('server'))> doesn't
1020 makes much sense and most probably would produce unexpected
1021 result, so the method ignore 'utc' context and uses offset
1022 returned by L<Localtime> method.
1029 if ( defined $_[9] ) {
1030 return timegm(@_[0..5]) - $_[9];
1032 $tz = $self->Timezone( $tz );
1033 if ( $tz eq 'UTC' ) {
1034 return Time::Local::timegm(@_[0..5]);
1038 local $ENV{'TZ'} = $tz;
1039 ## Using POSIX::tzset fixes a bug where the TZ environment variable
1042 $rv = Time::Local::timelocal(@_[0..5]);
1044 POSIX::tzset(); # switch back to previouse value
1051 =head3 Timezone $context
1053 Returns the timezone name.
1055 Takes one argument, C<$context> argument which could be C<user>, C<server> or C<utc>.
1061 Default value is C<user> that mean it returns current user's Timezone value.
1065 If context is C<server> it returns value of the C<Timezone> RT config option.
1069 If both server's and user's timezone names are undefined returns 'UTC'.
1077 my $context = lc(shift);
1079 $context = 'utc' unless $context =~ /^(?:utc|server|user)$/i;
1082 if( $context eq 'user' ) {
1083 $tz = $self->CurrentUser->UserObj->Timezone;
1084 } elsif( $context eq 'server') {
1085 $tz = RT->Config->Get('Timezone');
1089 $tz ||= RT->Config->Get('Timezone') || 'UTC';
1090 $tz = 'UTC' if lc $tz eq 'gmt';
1095 eval "require RT::Date_Vendor";
1096 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Vendor.pm});
1097 eval "require RT::Date_Local";
1098 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Local.pm});