+ my $unix = shift || $self->Unix;
+ $unix = 0 unless $unix >= 0;
+
+ my @local;
+ if ($tz eq 'UTC') {
+ @local = gmtime($unix);
+ } else {
+ {
+ local $ENV{'TZ'} = $tz;
+ ## Using POSIX::tzset fixes a bug where the TZ environment variable
+ ## is cached.
+ POSIX::tzset();
+ @local = localtime($unix);
+ }
+ POSIX::tzset(); # return back previouse value
+ }
+ $local[5] += 1900; # change year to 4+ digits format
+ my $offset = Time::Local::timegm_nocheck(@local) - $unix;
+ return @local, $offset;
+}
+
+=head3 Timelocal $context @time
+
+Takes argument C<$context>, which determines whether we should
+treat C<@time> as "user local", "system" or "UTC" time.
+
+C<@time> is array returned by L<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 C<$offset> as ninth argument, it's used instead of
+C<$context>. It's done such way as code
+C<$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 L<Localtime> method.
+
+=cut
+
+sub Timelocal {
+ my $self = shift;
+ my $tz = shift;
+ if ( defined $_[9] ) {
+ return timegm(@_[0..5]) - $_[9];
+ } else {
+ $tz = $self->Timezone( $tz );
+ if ( $tz eq 'UTC' ) {
+ return Time::Local::timegm(@_[0..5]);
+ } else {
+ my $rv;
+ {
+ local $ENV{'TZ'} = $tz;
+ ## Using POSIX::tzset fixes a bug where the TZ environment variable
+ ## is cached.
+ POSIX::tzset();
+ $rv = Time::Local::timelocal(@_[0..5]);
+ };
+ POSIX::tzset(); # switch back to previouse value
+ return $rv;
+ }
+ }
+}
+
+
+=head3 Timezone $context
+
+Returns the timezone name.
+
+Takes one argument, C<$context> argument which could be C<user>, C<server> or C<utc>.