Draft
Refactor date/time handling to use ImpressCMS IPF standards#9
Conversation
…mestamp, icms_conv_nr2local) Co-authored-by: fiammybe <3736946+fiammybe@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor date and time handling to use ImpressCMS IPF standards
Refactor date/time handling to use ImpressCMS IPF standards
Mar 19, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP's native
date()is used throughout the module for formatting, bypassing ImpressCMS timezone support, locale-aware calendar handling, and numeral system conversion. This replaces those calls withformatTimestamp()andicms_conv_nr2local()across all affected files.Changes
src/event.php/src/calendar.php: Replacedate('Y', ...)/date('F', ...)withformatTimestamp()for year/month extraction used in sorted event groupingsrc/class/EventHandler.php: RefactorprepareEventForDisplay— replace alldate()calls withformatTimestamp()for comparisons and formatting; wrap day/year numerics withicms_conv_nr2local()for non-Arabic numeral locale supportsrc/blocks/events_upcoming.php: Replacedate($dateformat, $date)withformatTimestamp($date, 'custom', $dateformat)in bothevents_upcoming_showandevents_upcoming_menu_showOriginal prompt
Refactor the date and time handling in the
fiammybe/eventsrepository to use ImpressCMS IPF (Item Persistence Framework) standards.Goals:
Replace PHP
date()withformatTimestamp():src/event.php,src/calendar.php,src/class/EventHandler.php, andsrc/blocks/events_upcoming.php, replace calls todate()withformatTimestamp()to ensure localization and timezone support.date('Y', $timestamp)should becomeformatTimestamp($timestamp, 'Y').date('F', $timestamp)should becomeformatTimestamp($timestamp, 'F').Refactor
prepareEventForDisplayinsrc/class/EventHandler.php:formatted_dateto useformatTimestamp()for all date components (day, month, year).Update Block Handling in
src/blocks/events_upcoming.php:formatTimestamp($timestamp, 'custom', $dateformat)instead ofdate($dateformat, $timestamp).Incorporate Localization:
icms_conv_nr2local()where appropriate for numeric outputs like day numbers or years to support non-Arabic numeral locales.Technical Context:
fiammybe/eventsmasterdatetime-ipfThis refactor will simplify the code, improve internationalization (i18n), and make the module more robust across different ImpressCMS installations.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Identify date and time handling in this module that is not using ImpressCMS IPF standards and can be refactored to use those standards, simplyfying the code and making it less error-prone
Assistant: In the
fiammybe/eventsrepository, date and time handling frequently uses standard PHP functions likedate(),time(), and manual string formatting instead of adhering to ImpressCMS IPF (Item Persistence Framework) standards.Refactoring these to use ImpressCMS core functions like
formatTimestamp()andicms_conv_nr2local()would improve localization (supporting different calendars and timezones), simplify the code, and make it more consistent with the rest of the platform.Identified Areas for Refactoring
1. Use of
date()instead offormatTimestamp()Throughout the module, the PHP
date()function is used with hardcoded format strings. In ImpressCMS,formatTimestamp()should be used to ensure that user-defined date formats and timezones are respected.src/event.php(Lines 177-178):Refactor to: Use
formatTimestamp($timestamp, 'Y')andformatTimestamp($timestamp, 'F').src/class/EventHandler.php(Lines 37-56):The
prepareEventForDisplaymethod manually compares months and days usingdate('n', ...)anddate('j', ...).Refactor to: Use
formatTimestamp()with appropriate format characters (e.g., 'n' for month number, 'j' for day).src/blocks/events_upcoming.php(Lines 109-111):Refactor to:
formatTimestamp($event->getVar('date', 'e'), 'custom', $dateformat).2. Manual Date Logic for Display
In
src/class/EventHandler.php, there is complex logic to format "1-3 January" vs "1 January - 3 February".Refactor to: While ImpressCMS doesn't have a direct "date range" formatter, using
formatTimestampfor each component ensures that month names are localized (e.g., using_CAL_JANUARYdefinitions automatically via the core).3. Localization and Number Conversion
The module does not appear to use
icms_conv_nr2local()for numeric outputs in dates or lists.icms_conv_nr2local()to support locales that use non-Arabic numerals (e.g., Persian/Jalali).4. Database Queries and Current Time
In several places,
time()is used directly in SQL queries or criteria.This pull request was created from Copilot chat.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.