-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events: Convert event-list timestamp.
Convert server-side Unix timestamps to a human-readable format and client-side timezone for the block WordPress Event List.
- Loading branch information
Showing
3 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ function render( $attributes, $content, $block ) { | |
$content .= '<li class="wporg-marker-list-item">'; | ||
$content .= '<h3 class="wporg-marker-list-item__title"><a class="external-link" href="' . esc_url( $event->url ) . ' ">' . esc_html( $event->title ) . '</a></h3>'; | ||
$content .= '<div class="wporg-marker-list-item__location">' . esc_html( $event->location ) . '</div>'; | ||
$content .= '<div class="wporg-marker-list-item__date-time">' . esc_html( $event->timestamp ) . '</div>'; | ||
$content .= '<div class="wporg-marker-list-item__date-time" data-wc-events-list-timestamp="' . esc_html( $event->timestamp ) . '"></div>'; | ||
This comment has been minimized.
Sorry, something went wrong.
iandunn
Member
|
||
$content .= '</li>'; | ||
} | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
public_html/wp-content/themes/wporg-events-2023/src/event-list/view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Converts server-side Unix timestamps to a human-readable format and client-side timezone. | ||
window.addEventListener( 'load', () => { | ||
const timeElements = document.querySelectorAll( '.wporg-marker-list__container .wporg-marker-list-item__date-time' ); | ||
|
||
timeElements.forEach( ( element ) => { | ||
const timestamp = element.getAttribute( 'data-wc-events-list-timestamp' ); | ||
const options = { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
}; | ||
const localDate = new Date( parseInt( timestamp ) * 1000 ).toLocaleString( 'en-US', options ); | ||
element.textContent = localDate; | ||
} ); | ||
} ); |
🤔 I'm not seeing this enqueued in my local env or on production. Not sure why, though, it looks correct.