Skip to content

Commit 9ae732f

Browse files
authored
Fix: Use specified time formatting for Outbox Activities (#1537)
* Fix timestamp for Outbox Activities * Add changelog * Add const
1 parent 217e98c commit 9ae732f

File tree

11 files changed

+19
-13
lines changed

11 files changed

+19
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Use specified date format for `updated` field in Outbox-Activites.

includes/collection/class-outbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public static function get_activity( $outbox_item ) {
223223
}
224224

225225
if ( 'Update' === $type ) {
226-
$activity->set_updated( gmdate( 'Y-m-d H:i:s', strtotime( $outbox_item->post_modified ) ) );
226+
$activity->set_updated( gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, strtotime( $outbox_item->post_modified ) ) );
227227
}
228228

229229
/**

includes/constants.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
)
6565
);
6666

67+
\define( 'ACTIVITYPUB_DATE_TIME_RFC3339', 'Y-m-d\TH:i:s\Z' );
68+
6769
// Define Actor-Modes for the plugin.
6870
\define( 'ACTIVITYPUB_ACTOR_MODE', 'actor' );
6971
\define( 'ACTIVITYPUB_BLOG_MODE', 'blog' );

includes/model/class-application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function get_published() {
187187
$time = \time();
188188
}
189189

190-
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
190+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
191191
}
192192

193193
/**

includes/model/class-blog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function get_published() {
311311
$time = \time();
312312
}
313313

314-
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
314+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
315315
}
316316

317317
/**

includes/model/class-user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function get_image() {
226226
* @return false|string The date the user was created.
227227
*/
228228
public function get_published() {
229-
return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
229+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
230230
}
231231

232232
/**

includes/scheduler/class-actor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static function schedule_profile_update( $user_id ) {
139139
return;
140140
}
141141

142-
$actor->set_updated( gmdate( 'Y-m-d H:i:s', time() ) );
142+
$actor->set_updated( gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, time() ) );
143143

144144
add_to_outbox( $actor, 'Update', $user_id );
145145
}

includes/transformer/class-comment.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public function to_object() {
4949
$object->set_type( 'Note' );
5050

5151
$published = \strtotime( $comment->comment_date_gmt );
52-
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
52+
$object->set_published( \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $published ) );
5353

5454
$updated = \get_comment_meta( $comment->comment_ID, 'activitypub_comment_modified', true );
5555
if ( $updated > $published ) {
56-
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
56+
$object->set_updated( \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $updated ) );
5757
}
5858

5959
$object->set_content_map(
@@ -302,7 +302,7 @@ public function get_updated() {
302302
$published = \get_comment_meta( $this->item->comment_ID, 'activitypub_comment_published', true );
303303

304304
if ( $updated > $published ) {
305-
return \gmdate( 'Y-m-d\TH:i:s\Z', $updated );
305+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $updated );
306306
}
307307

308308
return null;
@@ -314,7 +314,7 @@ public function get_updated() {
314314
* @return string The published date of the comment.
315315
*/
316316
public function get_published() {
317-
return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( $this->item->comment_date_gmt ) );
317+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, \strtotime( $this->item->comment_date_gmt ) );
318318
}
319319

320320
/**

includes/transformer/class-post.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ protected function get_in_reply_to() {
573573
protected function get_published() {
574574
$published = \strtotime( $this->item->post_date_gmt );
575575

576-
return \gmdate( 'Y-m-d\TH:i:s\Z', $published );
576+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $published );
577577
}
578578

579579
/**
@@ -586,7 +586,7 @@ protected function get_updated() {
586586
$updated = \strtotime( $this->item->post_modified_gmt );
587587

588588
if ( $updated > $published ) {
589-
return \gmdate( 'Y-m-d\TH:i:s\Z', $updated );
589+
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $updated );
590590
}
591591

592592
return null;

tests/includes/collection/class-test-outbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public function test_update_activity_has_updated_attribute() {
454454

455455
// Verify the updated attribute is set and matches the post's modified date.
456456
$post = get_post( $id );
457-
$expected_updated = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) );
457+
$expected_updated = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $post->post_modified ) );
458458
$this->assertEquals( $expected_updated, $activity->get_updated() );
459459

460460
// Delete the Outbox item.

0 commit comments

Comments
 (0)