1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
6 # <sales@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.
75 use base qw/RT::Base/;
81 use vars qw($MINUTE $HOUR $DAY $WEEK $MONTH $YEAR);
87 $MONTH = 30.4375 * $DAY;
88 $YEAR = 365.25 * $DAY;
105 our @DAYS_OF_WEEK = (
116 'DefaultFormat', # loc
122 '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'} && $args{'Value'} =~ /\S/;
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, $error) = Time::ParseDate::parsedate(
215 UK => RT->Config->Get('DateDayBeforeMonth'),
216 PREFER_PAST => RT->Config->Get('AmbiguousDayInPast'),
217 PREFER_FUTURE => RT->Config->Get('AmbiguousDayInFuture'),
219 unless ( defined $date ) {
220 $RT::Logger->warning(
221 "Couldn't parse date '$args{'Value'}' by Time::ParseDate"
223 return $self->Unix(0);
226 # apply timezone offset
227 $date -= ($self->Localtime( $args{Timezone}, $date ))[9];
230 "RT::Date used Time::ParseDate to make '$args{'Value'}' $date\n"
233 return $self->Set( Format => 'unix', Value => $date);
237 "Unknown Date format: $args{'Format'}\n"
239 return $self->Unix(0);
247 Set the object's time to the current time. Takes no arguments
248 and returns unix time.
253 return $_[0]->Unix(time);
256 =head2 SetToMidnight [Timezone => 'utc']
258 Sets the date to midnight (at the beginning of the day).
259 Returns the unixtime at midnight.
267 Timezone context C<user>, C<server> or C<UTC>. See also L</Timezone>.
275 my %args = ( Timezone => '', @_ );
276 my $new = $self->Timelocal(
278 0,0,0,($self->Localtime( $args{'Timezone'} ))[3..9]
280 return $self->Unix( $new );
283 =head2 SetToStart PERIOD[, Timezone => 'utc' ]
285 Set to the beginning of the current PERIOD, which can be
286 "year", "month", "day", "hour", or "minute".
294 my $tz = $args{'Timezone'} || '';
295 my @localtime = $self->Localtime($tz);
296 #remove 'offset' so that DST is figured based on the resulting time.
299 # This is the cleanest way to implement it, I swear.
302 last if ($p eq 'MINUTE');
304 last if ($p eq 'HOUR');
306 last if ($p eq 'DAY');
308 last if ($p eq 'MONTH');
310 last if ($p eq 'YEAR');
311 $RT::Logger->warning("Couldn't find start date of '$p'.");
314 my $new = $self->Timelocal($tz, @localtime);
315 return $self->Unix($new);
320 Takes either an C<RT::Date> object or the date in unixtime format as a string,
321 if nothing is specified uses the current time.
323 Returns the differnce between the time in the current object and that time
324 as a number of seconds. Returns C<undef> if any of two compared values is
325 incorrect or not set.
332 $other = time unless defined $other;
333 if ( UNIVERSAL::isa( $other, 'RT::Date' ) ) {
334 $other = $other->Unix;
336 return undef unless $other=~ /^\d+$/ && $other > 0;
338 my $unix = $self->Unix;
339 return undef unless $unix > 0;
341 return $unix - $other;
346 Takes either an C<RT::Date> object or the date in unixtime format as a string,
347 if nothing is specified uses the current time.
349 Returns the differnce between C<$self> and that time as a number of seconds as
350 a localized string fit for human consumption. Returns empty string if any of
351 two compared values is incorrect or not set.
357 my $diff = $self->Diff( @_ );
358 return '' unless defined $diff;
360 return $self->DurationAsString( $diff );
363 =head2 DurationAsString
365 Takes a number of seconds. Returns a localized string describing
370 sub DurationAsString {
372 my $duration = int shift;
374 my ( $negative, $s, $time_unit );
375 $negative = 1 if $duration < 0;
376 $duration = abs $duration;
378 if ( $duration < $MINUTE ) {
380 $time_unit = $self->loc("sec");
382 elsif ( $duration < ( 2 * $HOUR ) ) {
383 $s = int( $duration / $MINUTE + 0.5 );
384 $time_unit = $self->loc("min");
386 elsif ( $duration < ( 2 * $DAY ) ) {
387 $s = int( $duration / $HOUR + 0.5 );
388 $time_unit = $self->loc("hours");
390 elsif ( $duration < ( 2 * $WEEK ) ) {
391 $s = int( $duration / $DAY + 0.5 );
392 $time_unit = $self->loc("days");
394 elsif ( $duration < ( 2 * $MONTH ) ) {
395 $s = int( $duration / $WEEK + 0.5 );
396 $time_unit = $self->loc("weeks");
398 elsif ( $duration < $YEAR ) {
399 $s = int( $duration / $MONTH + 0.5 );
400 $time_unit = $self->loc("months");
403 $s = int( $duration / $YEAR + 0.5 );
404 $time_unit = $self->loc("years");
408 return $self->loc( "[_1] [_2] ago", $s, $time_unit );
411 return $self->loc( "[_1] [_2]", $s, $time_unit );
417 Takes nothing. Returns a string that's the differnce between the
418 time in the object and now.
422 sub AgeAsString { return $_[0]->DiffAsString }
428 Returns the object's time as a localized string with curent user's prefered
431 If the current user didn't choose prefered format then system wide setting is
432 used or L</DefaultFormat> if the latter is not specified. See config option
441 return $self->loc("Not set") unless $self->Unix > 0;
443 my $format = RT->Config->Get( 'DateTimeFormat', $self->CurrentUser ) || 'DefaultFormat';
444 $format = { Format => $format } unless ref $format;
445 %args = (%$format, %args);
447 return $self->Get( Timezone => 'user', %args );
450 =head2 GetWeekday DAY
452 Takes an integer day of week and returns a localized string for
453 that day of week. Valid values are from range 0-6, Note that B<0
462 return $self->loc($DAYS_OF_WEEK[$dow])
463 if $DAYS_OF_WEEK[$dow];
467 =head2 GetMonth MONTH
469 Takes an integer month and returns a localized string for that month.
470 Valid values are from from range 0-11.
478 return $self->loc($MONTHS[$mon])
483 =head2 AddSeconds SECONDS
485 Takes a number of seconds and returns the new unix time.
487 Negative value can be used to substract seconds.
493 my $delta = shift or return $self->Unix;
495 $self->Set(Format => 'unix', Value => ($self->Unix + $delta));
497 return ($self->Unix);
500 =head2 AddDays [DAYS]
502 Adds C<24 hours * DAYS> to the current time. Adds one day when
503 no argument is specified. Negative value can be used to substract
506 Returns new unix time.
512 my $days = shift || 1;
513 return $self->AddSeconds( $days * $DAY );
518 Adds 24 hours to the current time. Returns new unix time.
522 sub AddDay { return $_[0]->AddSeconds($DAY) }
526 Adds one month to the current time. Returns new
534 my @localtime = $self->Localtime($args{'Timezone'});
535 # remove offset, as with SetToStart
538 $localtime[4]++; #month
539 if ( $localtime[4] == 12 ) {
541 $localtime[5]++; #year
544 my $new = $self->Timelocal($args{'Timezone'}, @localtime);
545 return $self->Unix($new);
548 =head2 Unix [unixtime]
550 Optionally takes a date in unix seconds since the epoch format.
551 Returns the number of seconds since the epoch
557 $self->{'time'} = int(shift || 0) if @_;
558 return $self->{'time'};
563 Alias for L</Get> method. Arguments C<Date> and <Time>
564 are fixed to true values, other arguments could be used
565 as described in L</Get>.
571 unless (defined $self) {
572 use Carp; Carp::confess("undefined $self");
574 return $self->Get( @_, Date => 1, Time => 1 );
579 Takes Format argument which allows you choose date formatter.
580 Pass throught other arguments to the formatter method.
582 Returns the object's formatted date. Default formatter is ISO.
588 return $self->Get( @_, Date => 1, Time => 0 );
598 return $self->Get( @_, Date => 0, Time => 1 );
603 Returnsa a formatted and localized string that represets time of
612 my %args = (Format => 'ISO', @_);
613 my $formatter = $args{'Format'};
614 unless ( $self->ValidFormatter($formatter) ) {
615 RT->Logger->warning("Invalid date formatter '$formatter', falling back to ISO");
618 $formatter = 'ISO' unless $self->can($formatter);
619 return $self->$formatter( %args );
622 =head2 Output formatters
624 Fomatter is a method that returns date and time in different configurable
627 Each method takes several arguments:
635 =item Timezone - Timezone context C<server>, C<user> or C<UTC>
639 Formatters may also add own arguments to the list, for example
640 in RFC2822 format day of time in output is optional so it
641 understand boolean argument C<DayOfTime>.
645 Returns an array of available formatters.
656 =head3 ValidFormatter FORMAT
658 Returns a true value if C<FORMAT> is a known formatter. Otherwise returns
666 return (grep { $_ eq $format } $self->Formatters and $self->can($format))
677 my %args = ( Date => 1,
684 # 0 1 2 3 4 5 6 7 8 9
685 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
686 $self->Localtime($args{'Timezone'});
687 $wday = $self->GetWeekday($wday);
688 $mon = $self->GetMonth($mon);
689 ($mday, $hour, $min, $sec) = map { sprintf "%02d", $_ } ($mday, $hour, $min, $sec);
691 if( $args{'Date'} && !$args{'Time'} ) {
692 return $self->loc('[_1] [_2] [_3] [_4]',
693 $wday,$mon,$mday,$year);
694 } elsif( !$args{'Date'} && $args{'Time'} ) {
695 if( $args{'Seconds'} ) {
696 return $self->loc('[_1]:[_2]:[_3]',
699 return $self->loc('[_1]:[_2]',
703 if( $args{'Seconds'} ) {
704 return $self->loc('[_1] [_2] [_3] [_4]:[_5]:[_6] [_7]',
705 $wday,$mon,$mday,$hour,$min,$sec,$year);
707 return $self->loc('[_1] [_2] [_3] [_4]:[_5] [_6]',
708 $wday,$mon,$mday,$hour,$min,$year);
715 Returns the L<DateTime::Locale> object representing the current user's locale.
722 my $lang = $self->CurrentUser->UserObj->Lang;
724 require I18N::LangTags::Detect;
725 $lang = ( I18N::LangTags::Detect::detect(), 'en' )[0];
728 return DateTime::Locale->load($lang);
731 =head3 LocalizedDateTime
733 Returns date and time as string, with user localization.
735 Supports arguments: C<DateFormat> and C<TimeFormat> which may contains date and
736 time format as specified in L<DateTime::Locale> (default to full_date_format and
737 medium_time_format), C<AbbrDay> and C<AbbrMonth> which may be set to 0 if
738 you want full Day/Month names instead of abbreviated ones.
742 sub LocalizedDateTime
745 my %args = ( Date => 1,
755 # Require valid names for the format methods
756 my $date_format = $args{DateFormat} =~ /^\w+$/
757 ? $args{DateFormat} : 'date_format_full';
759 my $time_format = $args{TimeFormat} =~ /^\w+$/
760 ? $args{TimeFormat} : 'time_format_medium';
762 my $formatter = $self->LocaleObj;
763 $date_format = $formatter->$date_format;
764 $time_format = $formatter->$time_format;
765 $date_format =~ s/EEEE/EEE/g if ( $args{'AbbrDay'} );
766 $date_format =~ s/MMMM/MMM/g if ( $args{'AbbrMonth'} );
768 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
769 $self->Localtime($args{'Timezone'});
771 my $tz = $self->Timezone($args{'Timezone'});
773 # FIXME : another way to call this module without conflict with local
775 my $dt = DateTime::->new( locale => $formatter,
786 if ( $args{'Date'} && !$args{'Time'} ) {
787 return $dt->format_cldr($date_format);
788 } elsif ( !$args{'Date'} && $args{'Time'} ) {
789 return $dt->format_cldr($time_format);
791 return $dt->format_cldr($date_format) . " " . $dt->format_cldr($time_format);
797 Returns the object's date in ISO format C<YYYY-MM-DD mm:hh:ss>.
798 ISO format is locale independant, but adding timezone offset info
799 is not implemented yet.
801 Supports arguments: C<Timezone>, C<Date>, C<Time> and C<Seconds>.
802 See </Output formatters> for description of arguments.
808 my %args = ( Date => 1,
814 # 0 1 2 3 4 5 6 7 8 9
815 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
816 $self->Localtime($args{'Timezone'});
818 #the month needs incrementing, as gmtime returns 0-11
822 $res .= sprintf("%04d-%02d-%02d", $year, $mon, $mday) if $args{'Date'};
823 $res .= sprintf(' %02d:%02d', $hour, $min) if $args{'Time'};
824 $res .= sprintf(':%02d', $sec, $min) if $args{'Time'} && $args{'Seconds'};
832 Returns the object's date and time in W3C date time format
833 (L<http://www.w3.org/TR/NOTE-datetime>).
835 Format is locale independand and is close enought to ISO, but
836 note that date part is B<not optional> and output string
837 has timezone offset mark in C<[+-]hh:mm> format.
839 Supports arguments: C<Timezone>, C<Time> and C<Seconds>.
840 See </Output formatters> for description of arguments.
853 # 0 1 2 3 4 5 6 7 8 9
854 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
855 $self->Localtime( $args{'Timezone'} );
857 #the month needs incrementing, as gmtime returns 0-11
861 $res .= sprintf("%04d-%02d-%02d", $year, $mon, $mday);
862 if ( $args{'Time'} ) {
863 $res .= sprintf('T%02d:%02d', $hour, $min);
864 $res .= sprintf(':%02d', $sec, $min) if $args{'Seconds'};
866 $res .= sprintf "%s%02d:%02d", $self->_SplitOffset( $offset );
876 =head3 RFC2822 (MIME)
878 Returns the object's date and time in RFC2822 format,
879 for example C<Sun, 06 Nov 1994 08:49:37 +0000>.
880 Format is locale independand as required by RFC. Time
881 part always has timezone offset in digits with sign prefix.
883 Supports arguments: C<Timezone>, C<Date>, C<Time>, C<DayOfWeek>
884 and C<Seconds>. See </Output formatters> for description of
891 my %args = ( Date => 1,
899 # 0 1 2 3 4 5 6 7 8 9
900 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
901 $self->Localtime($args{'Timezone'});
903 my ($date, $time) = ('','');
904 $date .= "$DAYS_OF_WEEK[$wday], " if $args{'DayOfWeek'} && $args{'Date'};
905 $date .= sprintf("%02d %s %04d", $mday, $MONTHS[$mon], $year) if $args{'Date'};
907 if ( $args{'Time'} ) {
908 $time .= sprintf("%02d:%02d", $hour, $min);
909 $time .= sprintf(":%02d", $sec) if $args{'Seconds'};
910 $time .= sprintf " %s%02d%02d", $self->_SplitOffset( $offset );
913 return join ' ', grep $_, ($date, $time);
916 =head3 RFC2616 (HTTP)
918 Returns the object's date and time in RFC2616 (HTTP/1.1) format,
919 for example C<Sun, 06 Nov 1994 08:49:37 GMT>. While the RFC describes
920 version 1.1 of HTTP, but the same form date can be used in version 1.0.
922 Format is fixed length, locale independand and always represented in GMT
923 what makes it quite useless for users, but any date in HTTP transfers
924 must be presented using this format.
926 HTTP-date = rfc1123 | ...
927 rfc1123 = wkday "," SP date SP time SP "GMT"
928 date = 2DIGIT SP month SP 4DIGIT
929 ; day month year (e.g., 02 Jun 1982)
930 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
931 ; 00:00:00 - 23:59:59
932 wkday = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun"
933 month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun"
934 | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
936 Supports arguments: C<Date> and C<Time>, but you should use them only for
937 some personal reasons, RFC2616 doesn't define any optional parts.
938 See </Output formatters> for description of arguments.
944 my %args = ( Date => 1, Time => 1,
947 Seconds => 1, DayOfWeek => 1,
950 my $res = $self->RFC2822( %args );
951 $res =~ s/\s*[+-]\d\d\d\d$/ GMT/ if $args{'Time'};
957 Returns the object's date and time in iCalendar format,
959 Supports arguments: C<Date> and C<Time>.
960 See </Output formatters> for description of arguments.
967 Date => 1, Time => 1,
972 if ( $args{'Date'} && !$args{'Time'} ) {
973 my (undef, undef, undef, $mday, $mon, $year) =
974 $self->Localtime( 'user' );
975 $res = sprintf( '%04d%02d%02d', $year, $mon+1, $mday );
976 } elsif ( !$args{'Date'} && $args{'Time'} ) {
977 my ($sec, $min, $hour) =
978 $self->Localtime( 'utc' );
979 $res = sprintf( 'T%02d%02d%02dZ', $hour, $min, $sec );
981 my ($sec, $min, $hour, $mday, $mon, $year) =
982 $self->Localtime( 'utc' );
983 $res = sprintf( '%04d%02d%02dT%02d%02d%02dZ', $year, $mon+1, $mday, $hour, $min, $sec );
988 # it's been added by mistake in 3.8.0
989 sub iCalDate { return (shift)->iCal( Time => 0, @_ ) }
992 my ($self, $offset) = @_;
993 my $sign = $offset < 0? '-': '+';
994 $offset = int( (abs $offset) / 60 + 0.001 );
995 my $mins = $offset % 60;
996 my $hours = int( $offset/60 + 0.001 );
997 return $sign, $hours, $mins;
1000 =head2 Timezones handling
1002 =head3 Localtime $context [$time]
1004 Takes one mandatory argument C<$context>, which determines whether
1005 we want "user local", "system" or "UTC" time. Also, takes optional
1006 argument unix C<$time>, default value is the current unix time.
1008 Returns object's date and time in the format provided by perl's
1009 builtin functions C<localtime> and C<gmtime> with two exceptions:
1011 1) "Year" is a four-digit year, rather than "years since 1900"
1013 2) The last element of the array returned is C<offset>, which
1014 represents timezone offset against C<UTC> in seconds.
1021 my $tz = $self->Timezone(shift);
1023 my $unix = shift || $self->Unix;
1024 $unix = 0 unless $unix >= 0;
1028 @local = gmtime($unix);
1031 local $ENV{'TZ'} = $tz;
1032 ## Using POSIX::tzset fixes a bug where the TZ environment variable
1035 @local = localtime($unix);
1037 POSIX::tzset(); # return back previouse value
1039 $local[5] += 1900; # change year to 4+ digits format
1040 my $offset = Time::Local::timegm_nocheck(@local) - $unix;
1041 return @local, $offset;
1044 =head3 Timelocal $context @time
1046 Takes argument C<$context>, which determines whether we should
1047 treat C<@time> as "user local", "system" or "UTC" time.
1049 C<@time> is array returned by L<Localtime> functions. Only first
1050 six elements are mandatory - $sec, $min, $hour, $mday, $mon and $year.
1051 You may pass $wday, $yday and $isdst, these are ignored.
1053 If you pass C<$offset> as ninth argument, it's used instead of
1054 C<$context>. It's done such way as code
1055 C<$self->Timelocal('utc', $self->Localtime('server'))> doesn't
1056 makes much sense and most probably would produce unexpected
1057 result, so the method ignore 'utc' context and uses offset
1058 returned by L<Localtime> method.
1065 if ( defined $_[9] ) {
1066 return timegm(@_[0..5]) - $_[9];
1068 $tz = $self->Timezone( $tz );
1069 if ( $tz eq 'UTC' ) {
1070 return Time::Local::timegm(@_[0..5]);
1074 local $ENV{'TZ'} = $tz;
1075 ## Using POSIX::tzset fixes a bug where the TZ environment variable
1078 $rv = Time::Local::timelocal(@_[0..5]);
1080 POSIX::tzset(); # switch back to previouse value
1087 =head3 Timezone $context
1089 Returns the timezone name.
1091 Takes one argument, C<$context> argument which could be C<user>, C<server> or C<utc>.
1097 Default value is C<user> that mean it returns current user's Timezone value.
1101 If context is C<server> it returns value of the C<Timezone> RT config option.
1105 If both server's and user's timezone names are undefined returns 'UTC'.
1115 Carp::carp "RT::Date->Timezone is a setter only";
1119 my $context = lc(shift);
1121 $context = 'utc' unless $context =~ /^(?:utc|server|user)$/i;
1124 if( $context eq 'user' ) {
1125 $tz = $self->CurrentUser->UserObj->Timezone;
1126 } elsif( $context eq 'server') {
1127 $tz = RT->Config->Get('Timezone');
1131 $tz ||= RT->Config->Get('Timezone') || 'UTC';
1132 $tz = 'UTC' if lc $tz eq 'gmt';
1137 RT::Base->_ImportOverlays();