1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2024-11-28 05:24:10 +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)
* | `dtstart` | bool | Mention the start date (true)
* | `include_start` | bool |
* | `start_time_only` | bool | Mention the time of day only, without the date
* | `include_until` | bool |
* | `custom_path` | string |
*
@ -2091,6 +2092,7 @@ class RRule implements RRuleInterface
'fallback' => 'en',
'explicit_infinite' => true,
'include_start' => true,
'start_time_only' => false,
'include_until' => true,
'custom_path' => null
);
@ -2106,7 +2108,7 @@ class RRule implements RRuleInterface
}
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'])) {
$default_opt['time_format'] = \IntlDateFormatter::LONG;
}
@ -2114,7 +2116,7 @@ class RRule implements RRuleInterface
$default_opt['time_format'] = \IntlDateFormatter::SHORT;
}
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 {
$opt['date_formatter'] = function($date) {
return $date->format('Y-m-d H:i:s');
$opt['date_formatter'] = function ($date) use ($opt) {
$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']) {
// 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)
));
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

@ -3204,6 +3204,18 @@ class RRuleTest extends TestCase
"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(
"RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=+2TU",
array('locale' => "en", 'include_start' => false, 'explicit_infinite' => false),