Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar Start Date Issue in Grid View #567

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions includes/calendars/views/default-calendar-grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use SimpleCalendar\Abstracts\Calendar_View;
use SimpleCalendar\Events\Event;
use SimpleCalendar\Calendars\Default_Calendar;
use \DateTime;
use \DateTimeZone;

if (!defined('ABSPATH')) {
exit();
Expand Down Expand Up @@ -164,6 +166,20 @@ public function styles()
];
}

/**
* Format the timestamp with timeZone to display exact month as per the diffrent timezone.
*
* @since 3.4.3
*/
public function format_timestamp($format = 'F', $timestamp)
{
$datetime = new \DateTime();
$datetime->setTimezone(new \DateTimeZone($this->calendar->timezone));
$datetime->setTimestamp($timestamp);
$formatted_date = $datetime->format($format);

return $formatted_date;
}
/**
* Default calendar grid markup.
*
Expand Down Expand Up @@ -215,7 +231,7 @@ class="simcal-nav simcal-current"
}

foreach ($current as $k => $v) {
echo ' <span class="simcal-current-' . $k, '">' . date_i18n($v, $calendar->start) . '</span> ';
echo ' <span class="simcal-current-' . $k, '">' . $this->format_timestamp($v, $calendar->start) . '</span> ';
}

echo '</h3>';
Expand Down Expand Up @@ -264,7 +280,10 @@ class="simcal-nav simcal-current"
</tr>
</thead>

<?php echo $this->draw_month(date('n', $calendar->start), date('Y', $calendar->start)); ?>
<?php echo $this->draw_month(
date($this->format_timestamp('n', $calendar->start)),
date($this->format_timestamp('Y', $calendar->start))
); ?>
</table>

<?php
Expand Down