madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r20232: LJSUP-9828: fixed now time is correct

Committer: sbelyaev
LJSUP-9828: fixed now time is correct
U   trunk/cgi-bin/LJ/DelayedEntry.pm
Modified: trunk/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/DelayedEntry.pm	2011-10-05 08:34:20 UTC (rev 20231)
+++ trunk/cgi-bin/LJ/DelayedEntry.pm	2011-10-05 09:22:50 UTC (rev 20232)
@@ -135,7 +135,7 @@
     return $self->{logtime};
 }
 
-sub posttime {
+sub system_posttime {
     my ($self) = @_;
     return $self->{posttime};
 }
@@ -143,10 +143,31 @@
 sub posttime_as_unixtime {
     my ($self) = @_;
     my $dbh = LJ::get_db_writer();
-    my $qposttime = $self->posttime;
-    return $dbh->selectrow_array("SELECT UNIX_TIMESTAMP($qposttime)");
-} 
+    my $qposttime = $self->system_posttime;
+    return $dbh->selectrow_array("SELECT UNIX_TIMESTAMP('$qposttime')");
+}
 
+
+sub posttime {
+    my ($self, $u) = @_;
+    my $posttime = $self->system_posttime;
+    my $timezone = $self->poster->prop("timezone");
+    if (!$timezone) {
+        return $posttime;
+    }
+    my $epoch =  $self->posttime_as_unixtime;
+    my $dt = DateTime->from_epoch( 'epoch' => $epoch );
+
+    $dt->set_time_zone( $timezone );
+
+    # make the proper date format
+    return sprintf("%04d-%02d-%02d %02d:%02d", $dt->year,
+                                               $dt->month,
+                                               $dt->day,
+                                               $dt->hour,
+                                               $dt->minute );
+}
+
 sub alldatepart {
     my ($self) = @_;
     return $self->{alldatepart};
@@ -640,7 +661,6 @@
     return $self;
 }
 
-
 sub get_entry_by_id {
     my ($class, $journal, $delayedid, $options) = @_;
     __assert($journal);
@@ -669,13 +689,13 @@
     #                                         $userid );
 
     my $tz = $user->prop("timezone");
-    my $timezones = DateTime::TimeZone->new( name => $tz );
+    my $daterequest;
+    if ($tz) {
+        my $timezones = DateTime::TimeZone->new( name => $tz );
 
-    my $dt = DateTime->now( 'time_zone' => 'UTC');
-    my $offset = $timezones->offset_for_datetime($dt); 
+        my $dt = DateTime->now( 'time_zone' => 'UTC');
+        my $offset = $timezones->offset_for_datetime($dt);
 
-    my $daterequest;
-    if ($tz) {
         $daterequest = "DATE_FORMAT(ADDDATE(posttime, INTERVAL $offset SECOND), \"$dateformat\") AS 'alldatepart', " .
                        "DATE_FORMAT(ADDDATE(logtime,  INTERVAL $offset SECOND), \"$dateformat\") AS 'system_alldatepart' ";
     } else {
@@ -760,7 +780,6 @@
     my $dbcr = LJ::get_cluster_def_reader($journal) 
         or die "get cluster for journal failed";
 
-
     unless ($userid) {
         my $remote = LJ::get_remote();
         return undef unless $remote;
@@ -1107,6 +1126,7 @@
 sub handle_prefetched_props {
     my ($self) = @_;
     #stab
+    return;
 }
 
 sub can_delete_delayed_item {

Tags: livejournal, madeon, 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