* @param $zone DateTimeZone: Timezone of $ts
* @todo handling of "o" format character for Iranian, Hebrew, Hijri & Thai?
*
+ * @throws MWException
* @return string
*/
function sprintfDate( $format, $ts, DateTimeZone $zone = null ) {
$thai = false;
$minguo = false;
$tenno = false;
+
+ if ( strlen( $ts ) !== 14 ) {
+ throw new MWException( __METHOD__ . ": The timestamp $ts should have 14 characters" );
+ }
+
+ if ( !ctype_digit( $ts ) ) {
+ throw new MWException( __METHOD__ . ": The timestamp $ts should be a number" );
+ }
+
for ( $p = 0; $p < strlen( $format ); $p++ ) {
$num = false;
$code = $format[$p];
<?php
class LanguageTest extends LanguageClassesTestCase {
-
function testLanguageConvertDoubleWidthToSingleWidth() {
$this->assertEquals(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
);
}
+ /**
+ * Test too short timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateTooShortTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
+ }
+
+ /**
+ * Test too long timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateTooLongTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
+ }
+
+ /**
+ * Test too short timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateNotAllDigitTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
+ }
+
/**
* @dataProvider provideSprintfDateSamples
*/