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

Added start date in TextTransformer #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 19 additions & 7 deletions src/Recurr/Transformer/TextTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(TranslatorInterface $translator = null)
$this->translator = $translator ?: new Translator('en');
}

public function transform(Rule $rule)
public function transform(Rule $rule, $exclude = array())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function transform(Rule $rule, $exclude = array())
public function transform(Rule $rule, $exclude = [])

https://github.com/simshaun/recurr/blob/master/composer.json#L16

Old PHP 5.3 compat is not needed :) (https://github.com/wdes/coding-standard#rules-to-disable-for-php--54-compatibility)

{
$this->fragments = array();

Expand All @@ -39,16 +39,28 @@ public function transform(Rule $rule)
return $this->translator->trans('Unable to fully convert this rrule to text.');
}

$startDate = $rule->getStartDate();
if ($startDate instanceof \DateTimeInterface) {
if (!in_array('startDate', $exclude)) {
$dateFormatted = $this->translator->trans('day_date', array('date' => $startDate->format('U')));
$this->addFragment($this->translator->trans('from %date%', array('date' => $dateFormatted)));
}
}

$until = $rule->getUntil();
$count = $rule->getCount();
if ($until instanceof \DateTimeInterface) {
$dateFormatted = $this->translator->trans('day_date', array('date' => $until->format('U')));
$this->addFragment($this->translator->trans('until %date%', array('date' => $dateFormatted)));
if (!in_array('until', $exclude)) {
$dateFormatted = $this->translator->trans('day_date', array('date' => $until->format('U')));
$this->addFragment($this->translator->trans('until %date%', array('date' => $dateFormatted)));
}
} else if (!empty($count)) {
if ($this->isPlural($count)) {
$this->addFragment($this->translator->trans('for %count% times', array('count' => $count)));
} else {
$this->addFragment($this->translator->trans('for one time'));
if (!in_array('count', $exclude)) {
if ($this->isPlural($count)) {
$this->addFragment($this->translator->trans('for %count% times', array('count' => $count)));
} else {
$this->addFragment($this->translator->trans('for one time'));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions translations/da.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% gange',
'for one time' => 'en gang',
'(~ approximate)' => '(~ cirka)',
'from %date%' => 'fra %date%',
'until %date%' => 't.o.m. %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return date('j', $params['date']) . '. '. $months[date('n', $params['date']) - 1].date(', Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% Mal',
'for one time' => 'einmal',
'(~ approximate)' => '(~ ungefähr)',
'from %date%' => 'von %date%',
'until %date%' => 'bis %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4. Juli, 2014
return date('j. ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'for %count% times' => 'για %count% φορές',
'for one time' => 'για μία φορά',
'(~ approximate)' => '(~ κατά προσέγγιση)',
'from %date%' => 'από το %date%',
'until %date%' => 'μέχρι %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months_genitive) { // outputs a day date, e.g. 4 Ιουλίου 2014
return date('j', $params['date']) . ' ' . $months_genitive[date('n', $params['date']) - 1] . ' '. date('Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => 'for %count% times',
'for one time' => 'once',
'(~ approximate)' => '(~ approximate)',
'from %date%' => 'from %date%',
'until %date%' => 'until %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => 'para %count% veces',
'for one time' => 'por una vez',
'(~ approximate)' => '(~ aproximado)',
'from %date%' => 'desde %date%',
'until %date%' => 'hasta %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/eu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'for %count% times' => '%count% aldiz',
'for %count% time' => '%count% aldia',
'(~ approximate)' => '(~ inguru)',
'from %date%' => 'bertatik %date%',
'until %date%' => '%date% arte', // e.g. every year until July 4, 2014
'day_date' => defined('PHP_WINDOWS_VERSION_BUILD') ? '%B %#d, %Y' : '%B %e, %Y',
'and' => 'eta',
Expand Down
1 change: 1 addition & 0 deletions translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% fois',
'for one time' => 'une fois',
'(~ approximate)' => '(~ approximation)',
'from %date%' => 'à partir du %date%',
'until %date%' => 'jusqu\'au %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4 juillet, 2014
return date('j ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => 'per %count% volte',
'for one time' => 'per una volta',
'(~ approximate)' => '(~ approssimato)',
'from %date%' => 'a partire dal %date%',
'until %date%' => 'fino al %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. 4 luglio, 2014
return date('j ', $params['date']) . $months[date('n', $params['date']) - 1] . date(', Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => 'voor %count% keer',
'for one time' => 'eenmalig',
'(~ approximate)' => '(~ ongeveer)',
'from %date%' => 'van de %date%',
'until %date%' => 'tot en met %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return date('j', $params['date']).' '.$months[date('n', $params['date']) - 1] . ' '. date('Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/no.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% ganger',
'for one time' => 'en gang',
'(~ approximate)' => '(~ omtrent)',
'from %date%' => 'fra %date%',
'until %date%' => 'frem til %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/pt-br.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => 'por %count% vezes',
'for one time' => 'uma vez',
'(~ approximate)' => '(~ approximado)',
'from %date%' => 'do %date%',
'until %date%' => 'até %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return date('j', $params['date']) . ' de ' . $months[date('n', $params['date']) - 1] . ' de ' . date('Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/sv.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% gånger',
'for one time' => 'en gång',
'(~ approximate)' => '(~ ungefärlig)',
'until %date%' => 'från %date%',
'until %date%' => 't.o.m. %date%', // e.g. every year until July 4, 2014
'day_date' => function ($str, $params) use ($days, $months) { // outputs a day date, e.g. July 4, 2014
return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']);
Expand Down
1 change: 1 addition & 0 deletions translations/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'for %count% times' => '%count% kez',
'for one time' => 'bir kere',
'(~ approximate)' => '(~ yaklaşık)',
'from %date%' => 'itibaren %date%',
'until %date%' => 'kadar %date%', // e.g. 4 Temmuz 2014 e kadar her yıl
'day_date' => function ($str, $params) use ($days, $months) { // tarih çıktıları, e.g. Temmuz 4, 2014
return $months[date('n', $params['date']) - 1] . ' '. date('j, Y', $params['date']);
Expand Down