Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r20249: LJSUP-10071 (create a page with detailed...

Committer: ailyin
LJSUP-10071 (create a page with detailed status of svn repos on a server)
U   trunk/cgi-bin/LJ/TimeUtil.pm
Modified: trunk/cgi-bin/LJ/TimeUtil.pm
===================================================================
--- trunk/cgi-bin/LJ/TimeUtil.pm	2011-10-07 08:55:14 UTC (rev 20248)
+++ trunk/cgi-bin/LJ/TimeUtil.pm	2011-10-07 09:07:06 UTC (rev 20249)
@@ -2,6 +2,7 @@
 use strict;
 
 use DateTime;
+use HTTP::Date;
 
 # <LJFUNC>
 # name: LJ::TimeUtil->days_in_month
@@ -325,29 +326,26 @@
 =cut
 
 sub fancy_time_format {
-    my ($class, $timestamp, $precision) = @_;
+    my ( $class, $timestamp, $precision, $timezone ) = @_;
     $precision ||= 'sec';
+    $timezone ||= 'UTC';
 
-    my ($sec, $min, $hour, $mday, $mon, $year) = gmtime($timestamp);
+    my $dt = DateTime->from_epoch(
+        'epoch'     => $timestamp,
+        'time_zone' => $timezone,
+    );
 
-    # gmtime has returned month and year in a weird format; let's convert
-    # these to something more convenient
-    # reference: perldoc localtime
-    $mon  += 1;
-    $year += 1900;
+    my $month_code = lc LJ::Lang::month_short( $dt->month );
+    my $day_month  = LJ::Lang::ml( 'esn.month.day_' . $month_code,
+        { 'day' => $dt->day } );
 
-    my $month_code = lc(LJ::Lang::month_short($mon));
-    my $day_month  = LJ::Lang::ml("esn.month.day_$month_code", {
-        'day' => $mday,
-    });
-
-    my $ret = "$day_month $year";
+    my $ret = $day_month . ' ' . $dt->year;
     return $ret if $precision eq 'day';
 
-    $ret .= sprintf(', %02d:%02d', $hour, $min);
+    $ret .= sprintf( ', %02d:%02d', $dt->hour, $dt->minute );
     return $ret if $precision eq 'min';
 
-    $ret .= sprintf(':%02d', $sec);
+    $ret .= sprintf( ':%02d', $dt->second );
     return $ret if $precision eq 'sec';
 
     die "unknown precision $precision";

Tags: ailyin, andy, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments