1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-26 15:54:14 +01:00

Add human readable time of day option

This commit is contained in:
Jeff Bierschbach 2023-06-14 12:35:17 -05:00 committed by GitHub
parent 7ddef3d49b
commit bef5c05e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 49 additions and 5 deletions

View File

@ -2071,6 +2071,7 @@ class RRule implements RRuleInterface
* | `explicit_inifite`| bool | Mention "forever" if the rule is infinite (true) * | `explicit_inifite`| bool | Mention "forever" if the rule is infinite (true)
* | `dtstart` | bool | Mention the start date (true) * | `dtstart` | bool | Mention the start date (true)
* | `include_start` | bool | * | `include_start` | bool |
* | `start_time_only` | bool | Mention the time of day only, without the date
* | `include_until` | bool | * | `include_until` | bool |
* | `custom_path` | string | * | `custom_path` | string |
* *
@ -2091,6 +2092,7 @@ class RRule implements RRuleInterface
'fallback' => 'en', 'fallback' => 'en',
'explicit_infinite' => true, 'explicit_infinite' => true,
'include_start' => true, 'include_start' => true,
'start_time_only' => false,
'include_until' => true, 'include_until' => true,
'custom_path' => null 'custom_path' => null
); );
@ -2106,7 +2108,7 @@ class RRule implements RRuleInterface
} }
if ($opt['use_intl']) { if ($opt['use_intl']) {
$default_opt['date_format'] = \IntlDateFormatter::SHORT; $default_opt['date_format'] = isset($opt['start_time_only']) && $opt['start_time_only'] ? \IntlDateFormatter::NONE : \IntlDateFormatter::SHORT;
if ($this->freq >= self::SECONDLY || not_empty($this->rule['BYSECOND'])) { if ($this->freq >= self::SECONDLY || not_empty($this->rule['BYSECOND'])) {
$default_opt['time_format'] = \IntlDateFormatter::LONG; $default_opt['time_format'] = \IntlDateFormatter::LONG;
} }
@ -2114,7 +2116,7 @@ class RRule implements RRuleInterface
$default_opt['time_format'] = \IntlDateFormatter::SHORT; $default_opt['time_format'] = \IntlDateFormatter::SHORT;
} }
else { else {
$default_opt['time_format'] = \IntlDateFormatter::NONE; $default_opt['time_format'] = isset($opt['start_time_only']) && $opt['start_time_only'] ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE;
} }
} }
@ -2149,8 +2151,9 @@ class RRule implements RRuleInterface
}; };
} }
else { else {
$opt['date_formatter'] = function($date) { $opt['date_formatter'] = function ($date) use ($opt) {
return $date->format('Y-m-d H:i:s'); $format = $opt['start_time_only'] ? 'H:i:s' : 'Y-m-d H:i:s';
return $date->format($format);
}; };
} }
} }
@ -2362,7 +2365,12 @@ class RRule implements RRuleInterface
if ($opt['include_start']) { if ($opt['include_start']) {
// from X // from X
$parts['start'] = strtr($i18n['dtstart'], array( if ($opt['start_time_only']) {
$value = $this->freq >= self::HOURLY ? 'startingtimeofday' : 'timeofday';
} else {
$value = 'dtstart';
}
$parts['start'] = strtr($i18n[$value], array(
'%{date}' => $opt['date_formatter']($this->dtstart) '%{date}' => $opt['date_formatter']($this->dtstart)
)); ));
} }

View File

@ -44,6 +44,8 @@ return array(
'else' => 'Alle %{interval} Sekunden' 'else' => 'Alle %{interval} Sekunden'
), ),
'dtstart' => ', ab dem %{date}', 'dtstart' => ', ab dem %{date}',
'timeofday' => ' um %{date}',
'startingtimeofday' => ' ab %{date}',
'infinite' => ', für immer', 'infinite' => ', für immer',
'until' => ', bis zum %{date}', 'until' => ', bis zum %{date}',
'count' => array( 'count' => array(

View File

@ -46,6 +46,8 @@ return array(
'else' => 'every %{interval} seconds' 'else' => 'every %{interval} seconds'
), ),
'dtstart' => ', starting from %{date}', 'dtstart' => ', starting from %{date}',
'timeofday' => ' at %{date}',
'startingtimeofday' => ' starting at %{date}',
'infinite' => ', forever', 'infinite' => ', forever',
'until' => ', until %{date}', 'until' => ', until %{date}',
'count' => array( 'count' => array(

View File

@ -39,6 +39,8 @@ return array(
'else' => 'cada %{interval} segundos'// cada 8 segundos 'else' => 'cada %{interval} segundos'// cada 8 segundos
), ),
'dtstart' => ', empezando desde %{date}', 'dtstart' => ', empezando desde %{date}',
'timeofday' => ' a las %{date}',
'startingtimeofday' => ' empezando desde %{date}',
'infinite' => ', por siempre', 'infinite' => ', por siempre',
'until' => ', hasta %{date}', 'until' => ', hasta %{date}',
'count' => array( 'count' => array(

View File

@ -42,6 +42,8 @@ return array(
'else' => 'هر %{interval} ثانیه' 'else' => 'هر %{interval} ثانیه'
), ),
'dtstart' => ', از %{date}', 'dtstart' => ', از %{date}',
'timeofday' => ' از %{date}',
'startingtimeofday' => ' از %{date}',
'infinite' => ', همیشه', 'infinite' => ', همیشه',
'until' => ', تا %{date}', 'until' => ', تا %{date}',
'count' => array( 'count' => array(

View File

@ -46,6 +46,8 @@ return array(
'else' => 'joka %{interval} sekunti' 'else' => 'joka %{interval} sekunti'
), ),
'dtstart' => ', alkaen %{date}', 'dtstart' => ', alkaen %{date}',
'timeofday' => ' klo %{date}',
'startingtimeofday' => ' alkaen %{date}',
'infinite' => ', jatkuvasti', 'infinite' => ', jatkuvasti',
'until' => ', %{date} asti', 'until' => ', %{date} asti',
'count' => array( 'count' => array(

View File

@ -44,6 +44,8 @@ return array(
'else' => 'toutes les %{interval} secondes' 'else' => 'toutes les %{interval} secondes'
), ),
'dtstart' => ', à partir du %{date}', 'dtstart' => ', à partir du %{date}',
'timeofday' => ' à %{date}',
'startingtimeofday' => ' à partir du %{date}',
'infinite' => ', indéfiniment', 'infinite' => ', indéfiniment',
'until' => ', jusqu\'au %{date}', 'until' => ', jusqu\'au %{date}',
'count' => array( 'count' => array(

View File

@ -41,6 +41,8 @@ return array(
'else' => 'כל %{interval} שניות' 'else' => 'כל %{interval} שניות'
), ),
'dtstart' => ', החל מ%{date}', 'dtstart' => ', החל מ%{date}',
'timeofday' => ' החל מ%{date}',
'startingtimeofday' => ' החל מ%{date}',
'infinite' => ', לעד', 'infinite' => ', לעד',
'until' => ', עד %{date}', 'until' => ', עד %{date}',
'count' => array( 'count' => array(

View File

@ -38,6 +38,8 @@ return array(
'else' => 'ogni %{interval} secondi' 'else' => 'ogni %{interval} secondi'
), ),
'dtstart' => ', a partire dal %{date}', 'dtstart' => ', a partire dal %{date}',
'timeofday' => ' alle %{date}',
'startingtimeofday' => ' a partire dal %{date}',
'infinite' => ', per sempre', 'infinite' => ', per sempre',
'until' => ', fino al %{date}', 'until' => ', fino al %{date}',
'count' => array( 'count' => array(

View File

@ -46,6 +46,8 @@ return array(
'else' => 'elke %{interval} seconden' 'else' => 'elke %{interval} seconden'
), ),
'dtstart' => ', wordt gestart vanaf %{date}', 'dtstart' => ', wordt gestart vanaf %{date}',
'timeofday' => ' om %{date}',
'startingtimeofday' => ' wordt gestart vanaf %{date}',
'infinite' => ', oneindig', 'infinite' => ', oneindig',
'until' => ', tot en met %{date}', 'until' => ', tot en met %{date}',
'count' => array( 'count' => array(

View File

@ -58,6 +58,8 @@ return array(
'else' => 'co %{interval} sekund' 'else' => 'co %{interval} sekund'
), ),
'dtstart' => ', zaczynając od %{date}', 'dtstart' => ', zaczynając od %{date}',
'timeofday' => ' o %{date}',
'startingtimeofday' => ' zaczynając od %{date}',
'infinite' => ', zawsze', 'infinite' => ', zawsze',
'until' => ', do daty %{date}', 'until' => ', do daty %{date}',
'count' => array( 'count' => array(

View File

@ -39,6 +39,8 @@ return array(
'else' => 'cada %{interval} segundos'// cada 8 segundos 'else' => 'cada %{interval} segundos'// cada 8 segundos
), ),
'dtstart' => ', começando de %{date}', 'dtstart' => ', começando de %{date}',
'timeofday' => ' às %{date}',
'startingtimeofday' => ' começando de %{date}',
'infinite' => ', para sempre', 'infinite' => ', para sempre',
'until' => ', até %{date}', 'until' => ', até %{date}',
'count' => array( 'count' => array(

View File

@ -51,6 +51,8 @@ return array(
'else' => 'var %{interval}:e sekund' 'else' => 'var %{interval}:e sekund'
), ),
'dtstart' => ', börjar %{date}', 'dtstart' => ', börjar %{date}',
'timeofday' => ' kl %{date}',
'startingtimeofday' => ' börjar %{date}',
'infinite' => ', tills vidare', 'infinite' => ', tills vidare',
'until' => ', t.om %{date}', 'until' => ', t.om %{date}',
'count' => array( 'count' => array(

12
tests/RRuleTest.php Executable file → Normal file
View File

@ -3204,6 +3204,18 @@ class RRuleTest extends TestCase
"daily", "daily",
"daily" "daily"
), ),
array(
"DTSTART:20170202T161500Z\nRRULE:FREQ=MONTHLY;BYMONTHDAY=2",
array('locale' => "en", 'start_time_only' => true, 'explicit_infinite' => false),
"monthly on the 2nd of the month at 4:15 PM",
"monthly on the 2nd of the month at 16:15:00"
),
array(
"DTSTART:20170202T063000Z\nRRULE:FREQ=HOURLY;INTERVAL=7",
array('locale' => "en", 'start_time_only' => true, 'explicit_infinite' => false),
"every 7 hours starting at 6:30 AM",
"every 7 hours starting at 06:30:00"
),
array( array(
"RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=+2TU", "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=+2TU",
array('locale' => "en", 'include_start' => false, 'explicit_infinite' => false), array('locale' => "en", 'include_start' => false, 'explicit_infinite' => false),