Skip to content

[Locale] IntlDateFormatter #63

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8051e9a
[Locale] refactored Locale class
eriksencosta Jan 25, 2011
2850851
[Locale] renamed and simplified Locale::isIntlExtensionAvailable()
Jan 25, 2011
4c1ce75
[Locale] added intl's \Locale constants to the Locale class
Jan 25, 2011
2333ee3
[Locale] added NumberFormatterInterface
eriksencosta Jan 25, 2011
8f17d18
[Locale] added NumberFormatter class
Jan 25, 2011
5a51450
[Locale] changed NumberFormatInterface::getLocale() to use Locale::AC…
Jan 25, 2011
6672c39
[Locale] added SimpleNumberFormatter class (not finished)
Jan 26, 2011
d245fb8
[Locale] partialy implemented \NumberFormatter's format() and formatC…
Jan 29, 2011
af499ee
[Locale] partial impl of \NumberFormatter::parse()
eriksencosta Jan 30, 2011
8b99817
[Locale] extracted method
Feb 2, 2011
75b55ca
[Locale] extract method refactoring
Feb 2, 2011
1b0c671
[Locale] method throws exception for unsupported argument value
Feb 2, 2011
b198a9e
[Locale] refactored test code
Feb 2, 2011
ff6083f
[Locale] removed support for ceil and floor rounding modes as them do…
Feb 2, 2011
353418e
[Locale] updated docblock
Feb 2, 2011
1559557
[Locale] added implementation to getErrorCode and getErrorMessage met…
Feb 2, 2011
33bb0c0
[Locale] not implemented methods throws RuntimeException
Feb 2, 2011
cceeefd
[Locale] Removed NumberFormatterInterface and NumberFormatter wrapper…
Feb 5, 2011
4f024e3
[Locale] moved and renamed SimpleNumberFormatter to StubNumberFormatter
Feb 5, 2011
0aaf7b6
[Locale] added learning tests for the \NumberFormatter class
Feb 5, 2011
59a0f72
[Locale] first implementation of StubIntlDateFormatter
igorw Feb 5, 2011
3da4307
[Locale] add support for escaping, give specifics on implementation u…
igorw Feb 6, 2011
09b24fa
[Locale] move intl bugs to skipped tests
igorw Feb 6, 2011
43794ba
[Locale] support for G and Q placeholders in StubIntlDateFormatter::f…
igorw Feb 6, 2011
af6fae6
[Locale] add support for L, which is the same as M
igorw Feb 6, 2011
a91c970
[Locale] use assertSame instead of assertEquals
igorw Feb 6, 2011
c1aa274
[Locale] add support for h
igorw Feb 6, 2011
fec50dc
[Locale] support for D (day of year)
igorw Feb 6, 2011
b7f42f0
[Locale] support for E (day of week)
igorw Feb 6, 2011
d3e24d6
[Locale] support for a (AM/PM)
igorw Feb 6, 2011
85d05c8
[Locale] support for H (24 hour)
igorw Feb 6, 2011
0396dab
[Locale] refactor IntlDateFormatter::format to build regExp dynamically
igorw Feb 6, 2011
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
Prev Previous commit
Next Next commit
[Locale] add support for escaping, give specifics on implementation u…
…sed in tests
  • Loading branch information
igorw committed Feb 6, 2011
commit 3da43071da3fffc1baf44103dba34ee6847037ce
8 changes: 7 additions & 1 deletion src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca

public function format($timestamp)
{
$regExp = "/('(M+|y+|d+|[^Myd])|M+|y+|d+)/";

$callback = function($matches) use ($timestamp) {
$pattern = $matches[0];
$length = strlen($pattern);

if ("'" === $pattern[0]) {
return substr($pattern, 1);
}

switch ($pattern[0]) {
case 'M':
$matchLengthMap = array(
Expand Down Expand Up @@ -83,7 +89,7 @@ public function format($timestamp)
}
};

$formatted = preg_replace_callback('/(M+|y+|d+)/', $callback, $this->getPattern());
$formatted = preg_replace_callback($regExp, $callback, $this->getPattern());

return $formatted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function formatProvider()
return array(
array('y-M-d', 0, '1970-1-1'),

/* escaping */
array("'M", 0, 'M'),
array("'y-'M-'d", 0, 'y-M-d'),
array("'yy", 0, 'yy'),
array("'''yy", 0, "'yy"),
array("''y", 0, "'1970"),
array("''yy", 0, "'70"),

/* months */
array('M', 0, '1'),
array('MM', 0, '01'),
Expand Down Expand Up @@ -65,11 +73,11 @@ public function testConstructor()
public function testFormat($pattern, $timestamp, $expected)
{
$formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC', StubIntlDateFormatter::GREGORIAN, $pattern);
$this->assertEquals($expected, $formatter->format($timestamp));
$this->assertEquals($expected, $formatter->format($timestamp), 'Check date format with stub implementation.');

if (extension_loaded('intl')) {
$formatter = new \IntlDateFormatter('en', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
$this->assertEquals($expected, $formatter->format($timestamp));
$this->assertEquals($expected, $formatter->format($timestamp), 'Check date format with intl extension.');
}
}

Expand Down