Best JavaScript code snippet using best
format.js
Source:format.js
1define([2 "cldr",3 "src/date/format",4 "src/date/format-properties",5 "src/util/string/pad",6 "json!cldr-data/main/de/ca-gregorian.json",7 "json!cldr-data/main/en/ca-gregorian.json",8 "json!cldr-data/main/en/timeZoneNames.json",9 "json!cldr-data/main/en-GB/ca-gregorian.json",10 "json!cldr-data/main/en-GB/timeZoneNames.json",11 "json!cldr-data/main/en-IN/ca-gregorian.json",12 "json!cldr-data/main/pt/ca-gregorian.json",13 "json!cldr-data/main/ru/ca-gregorian.json",14 "json!cldr-data/supplemental/likelySubtags.json",15 "json!cldr-data/supplemental/metaZones.json",16 "json!cldr-data/supplemental/timeData.json",17 "json!cldr-data/supplemental/weekData.json",18 "json!iana-tz-data.json",19 "cldr/event",20 "cldr/supplemental"21], function( Cldr, format, formatProperties, stringPad, deCaGregorian, enCaGregorian,22 enTimeZoneNames, enGbCaGregorian, enGbTimeZoneNames, enInCaGregorian, ptCaGregorian,23 ruCaGregorian, likelySubtags, metaZones, timeData, weekData, ianaTimezoneData ) {24var cldr,25 year0 = new Date( -62167190400000 ),26 yearBc = new Date( -62482053600000 ),27 date1 = new Date( 1982, 0, 2, 9, 5, 59 ),28 date2 = new Date( 2010, 8, 15, 17, 35, 7, 369 ),29 date3 = new Date( 1981, 11, 31, 12 ), // thu30 date4 = new Date( 1994, 11, 31, 12 ); // sat31function FakeDate( timezoneOffset ) {32 this.timezoneOffset = timezoneOffset;33}34function simpleFormatter( pad ) {35 return function( value ) {36 return stringPad( value, pad );37 };38}39FakeDate.prototype.getTimezoneOffset = function() {40 return this.timezoneOffset * -60;41};42Cldr.load(43 deCaGregorian,44 enCaGregorian,45 enGbCaGregorian,46 enGbTimeZoneNames,47 enInCaGregorian,48 enTimeZoneNames,49 ptCaGregorian,50 ruCaGregorian,51 likelySubtags,52 metaZones,53 timeData,54 weekData55);56cldr = new Cldr( "en" );57Cldr.load({58 "main": {59 "en": {60 "dates": {61 "timeZoneNames": {62 "zone": {63 "Foo":{64 "Baz":{65 "exemplarCity": "Foo City"66 }67 }68 }69 }70 }71 }72 }73});74// Needed for globalizeDate.75Cldr.load({76 "globalize-iana": ianaTimezoneData77}, {78 "globalize-iana": {79 "zoneData": {80 "Foo": {81 "Bar": {82 offsets: ianaTimezoneData.zoneData.UTC.offsets,83 untils: ianaTimezoneData.zoneData.UTC.untils,84 isdsts: ianaTimezoneData.zoneData.UTC.isdsts85 },86 "Baz": {87 offsets: ianaTimezoneData.zoneData.UTC.offsets,88 untils: ianaTimezoneData.zoneData.UTC.untils,89 isdsts: ianaTimezoneData.zoneData.UTC.isdsts90 }91 }92 }93 }94});95QUnit.assert.dateFormat = function( date, pattern, cldr, expected ) {96 this.dateFormatWithTimezone( date, pattern, undefined, cldr, expected );97};98QUnit.assert.dateFormatWithTimezone = function( date, pattern, timeZone, cldr, expected ) {99 var pad,100 numberFormatters = [],101 properties = formatProperties( pattern, cldr, timeZone );102 // Create simple number formatters for this test purposes.103 for ( pad in properties.numberFormatters ) {104 numberFormatters[ pad ] = simpleFormatter( pad );105 }106 this.deepEqual( format( date, numberFormatters, properties ), expected );107};108QUnit.module( "Date Format" );109/**110 * Era111 */112QUnit.test( "should format era (G|GG|GGG)", function( assert ) {113 assert.dateFormat( date1, "G", cldr, [{114 type: "era",115 value: "AD"116 }]);117 assert.dateFormat( year0, "G", cldr, [{118 type: "era",119 value: "AD"120 }]);121 assert.dateFormat( yearBc, "G", cldr, [{122 type: "era",123 value: "BC"124 }]);125 assert.dateFormat( date1, "GG", cldr, [{126 type: "era",127 value: "AD"128 }]);129 assert.dateFormat( year0, "GG", cldr, [{130 type: "era",131 value: "AD"132 }]);133 assert.dateFormat( yearBc, "GG", cldr, [{134 type: "era",135 value: "BC"136 }]);137 assert.dateFormat( date1, "GGG", cldr, [{138 type: "era",139 value: "AD"140 }]);141 assert.dateFormat( year0, "GGG", cldr, [{142 type: "era",143 value: "AD"144 }]);145 assert.dateFormat( yearBc, "GGG", cldr, [{146 type: "era",147 value: "BC"148 }]);149});150QUnit.test( "should format era (GGGG)", function( assert ) {151 assert.dateFormat( date1, "GGGG", cldr, [{152 type: "era",153 value: "Anno Domini"154 }]);155 assert.dateFormat( year0, "GGGG", cldr, [{156 type: "era",157 value: "Anno Domini"158 }]);159 assert.dateFormat( yearBc, "GGGG", cldr, [{160 type: "era",161 value: "Before Christ"162 }]);163});164QUnit.test( "should format era (GGGGG)", function( assert ) {165 assert.dateFormat( date1, "GGGGG", cldr, [{166 type: "era",167 value: "A"168 }]);169 assert.dateFormat( year0, "GGGGG", cldr,[{170 type: "era",171 value: "A"172 }]);173 assert.dateFormat( yearBc, "GGGGG", cldr, [{174 type: "era",175 value: "B"176 }]);177});178/**179 * Year180 */181QUnit.test( "should format year (y) with no padding", function( assert ) {182 assert.dateFormat( date2, "y", cldr, [{183 type: "year",184 value: "2010"185 }]);186 assert.dateFormat( date1, "y", cldr, [{187 type: "year",188 value: "1982"189 }]);190 assert.dateFormat( year0, "y", cldr, [{191 type: "year",192 value: "0"193 }]);194});195QUnit.test( "should format year (yy) with padding, and limit 2 digits", function( assert ) {196 assert.dateFormat( date2, "yy", cldr, [{197 type: "year",198 value: "10"199 }]);200 assert.dateFormat( date1, "yy", cldr, [{201 type: "year",202 value: "82"203 }]);204 assert.dateFormat( year0, "yy", cldr, [{205 type: "year",206 value: "00"207 }]);208});209QUnit.test( "should format year (yyy+) with padding", function( assert ) {210 assert.dateFormat( date1, "yyy", cldr, [{211 type: "year",212 value: "1982"213 }]);214 assert.dateFormat( date2, "yyy", cldr, [{215 type: "year",216 value: "2010"217 }]);218 assert.dateFormat( year0, "yyyy", cldr, [{219 type: "year",220 value: "0000"221 }]);222 assert.dateFormat( date1, "yyyyy", cldr, [{223 type: "year",224 value: "01982"225 }]);226 assert.dateFormat( date2, "yyyyy", cldr, [{227 type: "year",228 value: "02010"229 }]);230});231QUnit.test( "should format year in \"week of year\" (Y) with no padding", function( assert ) {232 assert.dateFormat( date3, "Y", cldr, [{233 type: "year",234 value: "1982"235 }]);236 assert.dateFormat( date4, "Y", cldr, [{237 type: "year",238 value: "1994"239 }]);240});241QUnit.test( "should format year in \"week of year\" (YY) with padding, and limit 2 digits", function( assert ) {242 assert.dateFormat( date3, "YY", cldr, [{243 type: "year",244 value: "82"245 }]);246 assert.dateFormat( date4, "YY", cldr, [{247 type: "year",248 value: "94"249 }]);250});251QUnit.test( "should format year in \"week of year\" (YYY+) with padding", function( assert ) {252 assert.dateFormat( date3, "YYY", cldr, [{253 type: "year",254 value: "1982"255 }]);256 assert.dateFormat( date4, "YYY", cldr, [{257 type: "year",258 value: "1994"259 }]);260 assert.dateFormat( date3, "YYYYY", cldr, [{261 type: "year",262 value: "01982"263 }]);264 assert.dateFormat( date4, "YYYYY", cldr, [{265 type: "year",266 value: "01994"267 }]);268});269/**270 * Quarter271 */272QUnit.test( "should format quarter (Q|q) with no padding", function( assert ) {273 assert.dateFormat( date1, "Q", cldr, [{274 type: "quarter",275 value: "1"276 }]);277 assert.dateFormat( date2, "Q", cldr, [{278 type: "quarter",279 value: "3"280 }]);281 assert.dateFormat( date1, "q", cldr, [{282 type: "quarter",283 value: "1"284 }]);285 assert.dateFormat( date2, "q", cldr, [{286 type: "quarter",287 value: "3"288 }]);289});290QUnit.test( "should format quarter (QQ|qq) with padding", function( assert ) {291 assert.dateFormat( date1, "QQ", cldr, [{292 type: "quarter",293 value: "01"294 }]);295 assert.dateFormat( date2, "QQ", cldr, [{296 type: "quarter",297 value: "03"298 }]);299 assert.dateFormat( date1, "qq", cldr, [{300 type: "quarter",301 value: "01"302 }]);303 assert.dateFormat( date2, "qq", cldr, [{304 type: "quarter",305 value: "03"306 }]);307});308QUnit.test( "should format quarter (QQQ|qqq)", function( assert ) {309 assert.dateFormat( date1, "QQQ", cldr, [{310 type: "quarter",311 value: "Q1"312 }]);313 assert.dateFormat( date2, "QQQ", cldr, [{314 type: "quarter",315 value: "Q3"316 }]);317 assert.dateFormat( date1, "qqq", cldr, [{318 type: "quarter",319 value: "Q1"320 }]);321 assert.dateFormat( date2, "qqq", cldr, [{322 type: "quarter",323 value: "Q3"324 }]);325});326QUnit.test( "should format quarter (QQQQ|qqqq) with padding", function( assert ) {327 assert.dateFormat( date1, "QQQQ", cldr, [{328 type: "quarter",329 value: "1st quarter"330 }]);331 assert.dateFormat( date2, "QQQQ", cldr, [{332 type: "quarter",333 value: "3rd quarter"334 }]);335 assert.dateFormat( date1, "qqqq", cldr, [{336 type: "quarter",337 value: "1st quarter"338 }]);339 assert.dateFormat( date2, "qqqq", cldr, [{340 type: "quarter",341 value: "3rd quarter"342 }]);343});344/**345 * Month346 */347QUnit.test( "should format month (M|L) with no padding", function( assert ) {348 assert.dateFormat( date1, "M", cldr, [{349 type: "month",350 value: "1"351 }]);352 assert.dateFormat( date2, "M", cldr, [{353 type: "month",354 value: "9"355 }]);356 assert.dateFormat( date1, "L", cldr, [{357 type: "month",358 value: "1"359 }]);360 assert.dateFormat( date2, "L", cldr, [{361 type: "month",362 value: "9"363 }]);364});365QUnit.test( "should format month (MM|LL) with padding", function( assert ) {366 assert.dateFormat( date1, "MM", cldr, [{367 type: "month",368 value: "01"369 }]);370 assert.dateFormat( date2, "MM", cldr, [{371 type: "month",372 value: "09"373 }]);374 assert.dateFormat( date1, "LL", cldr, [{375 type: "month",376 value: "01"377 }]);378 assert.dateFormat( date2, "LL", cldr, [{379 type: "month",380 value: "09"381 }]);382});383QUnit.test( "should format month (MMM|LLL)", function( assert ) {384 assert.dateFormat( date1, "MMM", cldr, [{385 type: "month",386 value: "Jan"387 }]);388 assert.dateFormat( date2, "MMM", cldr, [{389 type: "month",390 value: "Sep"391 }]);392 assert.dateFormat( date1, "LLL", cldr, [{393 type: "month",394 value: "Jan"395 }]);396 assert.dateFormat( date2, "LLL", cldr, [{397 type: "month",398 value: "Sep"399 }]);400});401QUnit.test( "should format month (MMMM|LLLL)", function( assert ) {402 assert.dateFormat( date1, "MMMM", cldr, [{403 type: "month",404 value: "January"405 }]);406 assert.dateFormat( date2, "MMMM", cldr, [{407 type: "month",408 value: "September"409 }]);410 assert.dateFormat( date1, "LLLL", cldr, [{411 type: "month",412 value: "January"413 }]);414 assert.dateFormat( date2, "LLLL", cldr, [{415 type: "month",416 value: "September"417 }]);418});419QUnit.test( "should format month (MMMMM|LLLLL)", function( assert ) {420 assert.dateFormat( date1, "MMMMM", cldr, [{421 type: "month",422 value: "J"423 }]);424 assert.dateFormat( date2, "MMMMM", cldr, [{425 type: "month",426 value: "S"427 }]);428 assert.dateFormat( date1, "LLLLL", cldr, [{429 type: "month",430 value: "J"431 }]);432 assert.dateFormat( date2, "LLLLL", cldr, [{433 type: "month",434 value: "S"435 }]);436});437/**438 * Week439 */440QUnit.test( "should format week of year (w) with no padding", function( assert ) {441 assert.dateFormat( date1, "w", cldr, [{442 type: "week",443 value: "1"444 }]);445 assert.dateFormat( date2, "w", cldr, [{446 type: "week",447 value: "38"448 }]);449});450QUnit.test( "should format week of year (ww) with padding", function( assert ) {451 assert.dateFormat( date1, "ww", cldr, [{452 type: "week",453 value: "01"454 }]);455 assert.dateFormat( date2, "ww", cldr, [{456 type: "week",457 value: "38"458 }]);459});460QUnit.test( "should format week of month (W)", function( assert ) {461 assert.dateFormat( date1, "W", cldr, [{462 type: "week",463 value: "1"464 }]);465 assert.dateFormat( date2, "W", cldr, [{466 type: "week",467 value: "3"468 }]);469 assert.dateFormat( date3, "W", cldr, [{470 type: "week",471 value: "5"472 }]);473});474/**475 * Day476 */477QUnit.test( "should format day (d) with no padding", function( assert ) {478 assert.dateFormat( date1, "d", cldr, [{479 type: "day",480 value: "2"481 }]);482 assert.dateFormat( date2, "d", cldr, [{483 type: "day",484 value: "15"485 }]);486});487QUnit.test( "should format day (dd) with padding", function( assert ) {488 assert.dateFormat( date1, "dd", cldr, [{489 type: "day",490 value: "02"491 }]);492 assert.dateFormat( date2, "dd", cldr, [{493 type: "day",494 value: "15"495 }]);496});497QUnit.test( "should format day of year (D) with no padding", function( assert ) {498 assert.dateFormat( date1, "D", cldr, [{499 type: "day",500 value: "2"501 }]);502 assert.dateFormat( date2, "D", cldr, [{503 type: "day",504 value: "258"505 }]);506});507QUnit.test( "should format day of year (DD|DDD) with padding", function( assert ) {508 assert.dateFormat( date1, "DD", cldr, [{509 type: "day",510 value: "02"511 }]);512 assert.dateFormat( date1, "DDD", cldr, [{513 type: "day",514 value: "002"515 }]);516 assert.dateFormat( date2, "DD", cldr, [{517 type: "day",518 value: "258"519 }]);520});521QUnit.test( "should format day of week in month (F)", function( assert ) {522 assert.dateFormat( date1, "F", cldr, [{523 type: "day",524 value: "1"525 }]);526 assert.dateFormat( date2, "F", cldr, [{527 type: "day",528 value: "3"529 }]);530});531/**532 * Week day533 */534QUnit.test( "should format local day of week (e|c) with no padding", function( assert ) {535 assert.dateFormat( date1, "e", cldr, [{536 type: "weekday",537 value: "7"538 }]);539 assert.dateFormat( date2, "e", cldr, [{540 type: "weekday",541 value: "4"542 }]);543 assert.dateFormat( date1, "c", cldr, [{544 type: "weekday",545 value: "7"546 }]);547 assert.dateFormat( date2, "c", cldr, [{548 type: "weekday",549 value: "4"550 }]);551});552QUnit.test( "should format local day of week (ee|cc) with padding", function( assert ) {553 assert.dateFormat( date1, "ee", cldr, [{554 type: "weekday",555 value: "07"556 }]);557 assert.dateFormat( date2, "ee", cldr, [{558 type: "weekday",559 value: "04"560 }]);561 assert.dateFormat( date1, "cc", cldr, [{562 type: "weekday",563 value: "07"564 }]);565 assert.dateFormat( date2, "cc", cldr, [{566 type: "weekday",567 value: "04"568 }]);569});570QUnit.test( "should format local day of week (E|EE|EEE|eee|ccc)", function( assert ) {571 assert.dateFormat( date1, "E", cldr, [{572 type: "weekday",573 value: "Sat"574 }]);575 assert.dateFormat( date2, "E", cldr, [{576 type: "weekday",577 value: "Wed"578 }]);579 assert.dateFormat( date1, "EE", cldr, [{580 type: "weekday",581 value: "Sat"582 }]);583 assert.dateFormat( date2, "EE", cldr, [{584 type: "weekday",585 value: "Wed"586 }]);587 assert.dateFormat( date1, "EEE", cldr, [{588 type: "weekday",589 value: "Sat"590 }]);591 assert.dateFormat( date2, "EEE", cldr, [{592 type: "weekday",593 value: "Wed"594 }]);595 assert.dateFormat( date1, "eee", cldr, [{596 type: "weekday",597 value: "Sat"598 }]);599 assert.dateFormat( date2, "eee", cldr, [{600 type: "weekday",601 value: "Wed"602 }]);603 assert.dateFormat( date1, "ccc", cldr, [{604 type: "weekday",605 value: "Sat"606 }]);607 assert.dateFormat( date2, "ccc", cldr, [{608 type: "weekday",609 value: "Wed"610 }]);611});612QUnit.test( "should format local day of week (EEEE|eeee|cccc)", function( assert ) {613 assert.dateFormat( date1, "EEEE", cldr, [{614 type: "weekday",615 value: "Saturday"616 }]);617 assert.dateFormat( date2, "EEEE", cldr, [{618 type: "weekday",619 value: "Wednesday"620 }]);621 assert.dateFormat( date1, "eeee", cldr, [{622 type: "weekday",623 value: "Saturday"624 }]);625 assert.dateFormat( date2, "eeee", cldr, [{626 type: "weekday",627 value: "Wednesday"628 }]);629 assert.dateFormat( date1, "cccc", cldr, [{630 type: "weekday",631 value: "Saturday"632 }]);633 assert.dateFormat( date2, "cccc", cldr, [{634 type: "weekday",635 value: "Wednesday"636 }]);637});638QUnit.test( "should format local day of week (EEEEE|eeeee|ccccc)", function( assert ) {639 assert.dateFormat( date1, "EEEEE", cldr, [{640 type: "weekday",641 value: "S"642 }]);643 assert.dateFormat( date2, "EEEEE", cldr, [{644 type: "weekday",645 value: "W"646 }]);647 assert.dateFormat( date1, "eeeee", cldr, [{648 type: "weekday",649 value: "S"650 }]);651 assert.dateFormat( date2, "eeeee", cldr, [{652 type: "weekday",653 value: "W"654 }]);655 assert.dateFormat( date1, "ccccc", cldr, [{656 type: "weekday",657 value: "S"658 }]);659 assert.dateFormat( date2, "ccccc", cldr, [{660 type: "weekday",661 value: "W"662 }]);663});664QUnit.test( "should format local day of week (EEEEEE|eeeeee|cccccc)", function( assert ) {665 assert.dateFormat( date1, "EEEEEE", cldr, [{666 type: "weekday",667 value: "Sa"668 }]);669 assert.dateFormat( date2, "EEEEEE", cldr, [{670 type: "weekday",671 value: "We"672 }]);673 assert.dateFormat( date1, "eeeeee", cldr, [{674 type: "weekday",675 value: "Sa"676 }]);677 assert.dateFormat( date2, "eeeeee", cldr, [{678 type: "weekday",679 value: "We"680 }]);681 assert.dateFormat( date1, "cccccc", cldr, [{682 type: "weekday",683 value: "Sa"684 }]);685 assert.dateFormat( date2, "cccccc", cldr, [{686 type: "weekday",687 value: "We"688 }]);689});690/**691 * Period692 */693QUnit.test( "should format period (a)", function( assert ) {694 assert.dateFormat( date1, "a", cldr, [{695 type: "dayperiod",696 value: "AM"697 }]);698 assert.dateFormat( date2, "a", cldr, [{699 type: "dayperiod",700 value: "PM"701 }]);702});703/**704 * Hour705 */706QUnit.test( "should format hour (h) using 12-hour-cycle [1-12] with no padding", function( assert ) {707 assert.dateFormat( date1, "h", cldr, [{708 type: "hour",709 value: "9"710 }]);711 assert.dateFormat( date2, "h", cldr, [{712 type: "hour",713 value: "5"714 }]);715 assert.dateFormat( new Date( 0, 0, 0, 0 ), "h", cldr, [{716 type: "hour",717 value: "12"718 }]);719});720QUnit.test( "should format hour (hh) using 12-hour-cycle [1-12] with padding", function( assert ) {721 assert.dateFormat( date1, "hh", cldr, [{722 type: "hour",723 value: "09"724 }]);725 assert.dateFormat( date2, "hh", cldr, [{726 type: "hour",727 value: "05"728 }]);729 assert.dateFormat( new Date( 0, 0, 0, 0 ), "hh", cldr,[{730 type: "hour",731 value: "12"732 }]);733});734QUnit.test( "should format hour (H) using 24-hour-cycle [0-23] with no padding", function( assert ) {735 assert.dateFormat( date1, "H", cldr, [{736 type: "hour",737 value: "9"738 }]);739 assert.dateFormat( date2, "H", cldr, [{740 type: "hour",741 value: "17"742 }]);743 assert.dateFormat( new Date( 0, 0, 0, 0 ), "H", cldr, [{744 type: "hour",745 value: "0"746 }]);747});748QUnit.test( "should format hour (HH) using 24-hour-cycle [0-23] with padding", function( assert ) {749 assert.dateFormat( date1, "HH", cldr, [{750 type: "hour",751 value: "09"752 }]);753 assert.dateFormat( date2, "HH", cldr, [{754 type: "hour",755 value: "17"756 }]);757 assert.dateFormat( new Date( 0, 0, 0, 0 ), "HH", cldr, [{758 type: "hour",759 value: "00"760 }]);761});762QUnit.test( "should format hour (K) using 12-hour-cycle [0-11] with no padding", function( assert ) {763 assert.dateFormat( date1, "K", cldr, [{764 type: "hour",765 value: "9"766 }]);767 assert.dateFormat( date2, "K", cldr, [{768 type: "hour",769 value: "5"770 }]);771 assert.dateFormat( new Date( 0, 0, 0, 0 ), "K", cldr, [{772 type: "hour",773 value: "0"774 }]);775});776QUnit.test( "should format hour (KK) using 12-hour-cycle [0-11] with padding", function( assert ) {777 assert.dateFormat( date1, "KK", cldr, [{778 type: "hour",779 value: "09"780 }]);781 assert.dateFormat( date2, "KK", cldr, [{782 type: "hour",783 value: "05"784 }]);785 assert.dateFormat( new Date( 0, 0, 0, 0 ), "KK", cldr, [{786 type: "hour",787 value: "00"788 }]);789});790QUnit.test( "should format hour (k) using 24-hour-cycle [1-24] with no padding", function( assert ) {791 assert.dateFormat( date1, "k", cldr, [{792 type: "hour",793 value: "9"794 }]);795 assert.dateFormat( date2, "k", cldr, [{796 type: "hour",797 value: "17"798 }]);799 assert.dateFormat( new Date( 0, 0, 0, 0 ), "k", cldr, [{800 type: "hour",801 value: "24"802 }]);803});804QUnit.test( "should format hour (kk) using 24-hour-cycle [1-24] with padding", function( assert ) {805 assert.dateFormat( date1, "kk", cldr, [{806 type: "hour",807 value: "09"808 }]);809 assert.dateFormat( date2, "kk", cldr, [{810 type: "hour",811 value: "17"812 }]);813 assert.dateFormat( new Date( 0, 0, 0, 0 ), "kk", cldr, [{814 type: "hour",815 value: "24"816 }]);817});818QUnit.test( "should format hour (j) using preferred hour format for the locale (h, H, K, or k) with no padding", function( assert ) {819 assert.dateFormat( date2, "j", cldr, [{820 type: "hour",821 value: "5"822 }]);823 assert.dateFormat( date2, "j", new Cldr( "pt-BR" ), [{824 type: "hour",825 value: "17"826 }]);827 assert.dateFormat( date2, "j", new Cldr( "de" ), [{828 type: "hour",829 value: "17"830 }]);831 assert.dateFormat( date2, "j", new Cldr( "en-IN" ), [{832 type: "hour",833 value: "5"834 }]);835 assert.dateFormat( date2, "j", new Cldr( "en-GB" ), [{836 type: "hour",837 value: "17"838 }]);839 assert.dateFormat( date2, "j", new Cldr( "ru" ), [{840 type: "hour",841 value: "17"842 }]);843});844QUnit.test( "should format hour (jj) using preferred hour format for the locale (h, H, K, or k) with padding", function( assert ) {845 assert.dateFormat( date1, "jj", cldr, [{846 type: "hour",847 value: "09"848 }]);849 assert.dateFormat( date2, "jj", cldr, [{850 type: "hour",851 value: "05"852 }]);853 assert.dateFormat( new Date( 0, 0, 0, 0 ), "jj", cldr, [{854 type: "hour",855 value: "12"856 }]);857});858/**859 * Minute860 */861QUnit.test( "should format minute (m) with no padding", function( assert ) {862 assert.dateFormat( date1, "m", cldr, [{863 type: "minute",864 value: "5"865 }]);866 assert.dateFormat( date2, "m", cldr, [{867 type: "minute",868 value: "35"869 }]);870});871QUnit.test( "should format minute (mm) with padding", function( assert ) {872 assert.dateFormat( date1, "mm", cldr, [{873 type: "minute",874 value: "05"875 }]);876 assert.dateFormat( date2, "mm", cldr, [{877 type: "minute",878 value: "35"879 }]);880});881/**882 * Second883 */884QUnit.test( "should format second (s) with no padding", function( assert ) {885 assert.dateFormat( date1, "s", cldr, [{886 type: "second",887 value: "59"888 }]);889 assert.dateFormat( date2, "s", cldr, [{890 type: "second",891 value: "7"892 }]);893});894QUnit.test( "should format second (ss) with padding", function( assert ) {895 assert.dateFormat( date1, "ss", cldr, [{896 type: "second",897 value: "59"898 }]);899 assert.dateFormat( date2, "ss", cldr, [{900 type: "second",901 value: "07"902 }]);903});904QUnit.test( "should format various milliseconds (S+)", function( assert ) {905 assert.dateFormat( date2, "S", cldr, [{906 type: "second",907 value: "4"908 }]);909 assert.dateFormat( date2, "SS", cldr, [{910 type: "second",911 value: "37"912 }]);913 assert.dateFormat( date2, "SSS", cldr, [{914 type: "second",915 value: "369"916 }]);917 assert.dateFormat( date2, "SSSS", cldr, [{918 type: "second",919 value: "3690"920 }]);921 assert.dateFormat( date2, "SSSSS", cldr, [{922 type: "second",923 value: "36900"924 }]);925});926QUnit.test( "should format various milliseconds (A+)", function( assert ) {927 assert.dateFormat( date2, "A", cldr, [{928 type: "second",929 value: "633074"930 }]);931 assert.dateFormat( date2, "AA", cldr, [{932 type: "second",933 value: "6330737"934 }]);935 assert.dateFormat( date2, "AAA", cldr, [{936 type: "second",937 value: "63307369"938 }]);939 assert.dateFormat( date2, "AAAA", cldr, [{940 type: "second",941 value: "633073690"942 }]);943 assert.dateFormat( date2, "AAAAA", cldr, [{944 type: "second",945 value: "6330736900"946 }]);947});948/**949 * Zone950 */951QUnit.test( "should format timezone (z)", function( assert ) {952 var date,953 enGb = new Cldr( "en-GB" );954 // Test for country with Daylight Savings and Standard time, e.g., Pacific Standard Time and955 // Pacific Daylight Time.956 date = new Date( 2017, 0, 1 );957 assert.dateFormatWithTimezone( date, "z", "America/Los_Angeles", cldr, [{958 type: "zone",959 value: "PST"960 }]);961 assert.dateFormatWithTimezone( date, "zz", "America/Los_Angeles", cldr, [{962 type: "zone",963 value: "PST"964 }]);965 assert.dateFormatWithTimezone( date, "zzz", "America/Los_Angeles", cldr, [{966 type: "zone",967 value: "PST"968 }]);969 assert.dateFormatWithTimezone( date, "zzzz", "America/Los_Angeles", cldr, [{970 type: "zone",971 value: "Pacific Standard Time"972 }]);973 date = new Date( 2017, 6, 1 );974 assert.dateFormatWithTimezone( date, "z", "America/Los_Angeles", cldr, [{975 type: "zone",976 value: "PDT"977 }]);978 assert.dateFormatWithTimezone( date, "zz", "America/Los_Angeles", cldr, [{979 type: "zone",980 value: "PDT"981 }]);982 assert.dateFormatWithTimezone( date, "zzz", "America/Los_Angeles", cldr, [{983 type: "zone",984 value: "PDT"985 }]);986 assert.dateFormatWithTimezone( date, "zzzz", "America/Los_Angeles", cldr, [{987 type: "zone",988 value: "Pacific Daylight Time"989 }]);990 date = new Date( 2017, 0, 1 );991 assert.dateFormatWithTimezone( date, "zzzz", "Asia/Dubai", cldr, [{992 type: "zone",993 value: "Gulf Standard Time"994 }]);995 date = new Date( 2017, 6, 1 );996 assert.dateFormatWithTimezone( date, "zzzz", "Asia/Dubai", cldr, [{997 type: "zone",998 value: "Gulf Standard Time"999 }]);1000 // Test for two things:1001 // - daylightTzName using the zone data (primary), not the metazone (secondary try);1002 // - standardTzName being undefined, therefore requiring the O fallback properties;1003 date = new Date( "2015-06-01T12:32:46" );1004 assert.dateFormatWithTimezone( date, "z", "Europe/London", enGb, [{1005 type: "zone",1006 value: "BST"1007 }]);1008 assert.dateFormatWithTimezone( date, "zz", "Europe/London", enGb, [{1009 type: "zone",1010 value: "BST"1011 }]);1012 assert.dateFormatWithTimezone( date, "zzz", "Europe/London", enGb, [{1013 type: "zone",1014 value: "BST"1015 }]);1016 assert.dateFormatWithTimezone( date, "zzzz", "Europe/London", enGb, [{1017 type: "zone",1018 value: "British Summer Time"1019 }]);1020 date = new Date( "2015-01-01T12:32:46" );1021 assert.dateFormatWithTimezone( date, "z", "Europe/London", enGb, [{1022 type: "zone",1023 value: "GMT"1024 }]);1025 assert.dateFormatWithTimezone( date, "zz", "Europe/London", enGb, [{1026 type: "zone",1027 value: "GMT"1028 }]);1029 assert.dateFormatWithTimezone( date, "zzz", "Europe/London", enGb, [{1030 type: "zone",1031 value: "GMT"1032 }]);1033 assert.dateFormatWithTimezone( date, "zzzz", "Europe/London", enGb, [{1034 type: "zone",1035 value: "GMT"1036 }]);1037 // Test for country with only standard time, e.g., long: Indian Standard Time.1038 // This test also covers the case where timezone name is undefined like short timezone name for1039 // Asia/Calcutta and should fall through 'O' format.1040 // isDST === false.1041 date = new Date( 2017, 0, 1 );1042 assert.dateFormatWithTimezone( date, "z", "Asia/Calcutta", cldr, [{1043 type: "zone",1044 value: "GMT+5:30"1045 }]);1046 assert.dateFormatWithTimezone( date, "zz", "Asia/Calcutta", cldr, [{1047 type: "zone",1048 value: "GMT+5:30"1049 }]);1050 assert.dateFormatWithTimezone( date, "zzz", "Asia/Calcutta", cldr, [{1051 type: "zone",1052 value: "GMT+5:30"1053 }]);1054 assert.dateFormatWithTimezone( date, "zzzz", "Asia/Calcutta", cldr, [{1055 type: "zone",1056 value: "India Standard Time"1057 }]);1058 // isDST === true:1059 date = new Date( 1943, 0, 1 );1060 assert.dateFormatWithTimezone( date, "z", "Asia/Calcutta", cldr, [{1061 type: "zone",1062 value: "GMT+6:30"1063 }]);1064 assert.dateFormatWithTimezone( date, "zz", "Asia/Calcutta", cldr, [{1065 type: "zone",1066 value: "GMT+6:30"1067 }]);1068 assert.dateFormatWithTimezone( date, "zzz", "Asia/Calcutta", cldr, [{1069 type: "zone",1070 value: "GMT+6:30"1071 }]);1072 // Fall through to 'O' format1073 assert.dateFormatWithTimezone( date, "zzzz", "Asia/Calcutta", cldr, [{1074 type: "zone",1075 value: "GMT+06:30"1076 }]);1077 assert.dateFormatWithTimezone( date1, "z", "Foo/Bar", cldr, [{1078 type: "zone",1079 value: "GMT"1080 }]);1081 assert.dateFormatWithTimezone( date1, "zz", "Foo/Bar", cldr, [{1082 type: "zone",1083 value: "GMT"1084 }]);1085 assert.dateFormatWithTimezone( date1, "zzz", "Foo/Bar", cldr, [{1086 type: "zone",1087 value: "GMT"1088 }]);1089 assert.dateFormatWithTimezone( date1, "zzzz", "Foo/Bar", cldr, [{1090 type: "zone",1091 value: "GMT"1092 }]);1093});1094QUnit.test( "should format timezone (Z)", function( assert ) {1095 var date = new FakeDate( 0 );1096 assert.dateFormat( date, "Z", cldr, [{1097 type: "zone",1098 value: "+0000"1099 }]);1100 assert.dateFormat( date, "ZZ", cldr, [{1101 type: "zone",1102 value: "+0000"1103 }]);1104 assert.dateFormat( date, "ZZZ", cldr, [{1105 type: "zone",1106 value: "+0000"1107 }]);1108 assert.dateFormat( date, "ZZZZ", cldr,[{1109 type: "zone",1110 value: "GMT"1111 }]);1112 assert.dateFormat( date, "ZZZZZ", cldr, [{1113 type: "zone",1114 value: "Z"1115 }]);1116 date = new FakeDate( -3 );1117 assert.dateFormat( date, "Z", cldr, [{1118 type: "zone",1119 value: "-0300"1120 }]);1121 assert.dateFormat( date, "ZZ", cldr, [{1122 type: "zone",1123 value: "-0300"1124 }]);1125 assert.dateFormat( date, "ZZZ", cldr, [{1126 type: "zone",1127 value: "-0300"1128 }]);1129 assert.dateFormat( date, "ZZZZ", cldr, [{1130 type: "zone",1131 value: "GMT-03:00"1132 }]);1133 assert.dateFormat( date, "ZZZZZ", cldr, [{1134 type: "zone",1135 value: "-03:00"1136 }]);1137 date = new FakeDate( 11 );1138 assert.dateFormat( date, "Z", cldr, [{1139 type: "zone",1140 value: "+1100"1141 }]);1142 assert.dateFormat( date, "ZZ", cldr, [{1143 type: "zone",1144 value: "+1100"1145 }]);1146 assert.dateFormat( date, "ZZZ", cldr, [{1147 type: "zone",1148 value: "+1100"1149 }]);1150 assert.dateFormat( date, "ZZZZ", cldr, [{1151 type: "zone",1152 value: "GMT+11:00"1153 }]);1154 assert.dateFormat( date, "ZZZZZ", cldr, [{1155 type: "zone",1156 value: "+11:00"1157 }]);1158});1159QUnit.test( "should format timezone (O)", function( assert ) {1160 var date = new FakeDate( 0 );1161 assert.dateFormat( date, "O", cldr, [{1162 type: "zone",1163 value: "GMT" 1164 }]);1165 assert.dateFormat( date, "OOOO", cldr, [{1166 type: "zone",1167 value: "GMT" 1168 }]);1169 date = new FakeDate( -3 );1170 assert.dateFormat( date, "O", cldr, [{1171 type: "zone",1172 value: "GMT-3" 1173 }]);1174 assert.dateFormat( date, "OOOO", cldr, [{1175 type: "zone",1176 value: "GMT-03:00" 1177 }]);1178 date = new FakeDate( 11 );1179 assert.dateFormat( date, "O", cldr, [{1180 type: "zone",1181 value: "GMT+11" 1182 }]);1183 assert.dateFormat( date, "OOOO", cldr, [{1184 type: "zone",1185 value: "GMT+11:00" 1186 }]);1187 // TODO Support optional seconds.1188 date = new FakeDate( -7.883 );1189 assert.dateFormat( date, "O", cldr, [{1190 type: "zone",1191 value: "GMT-7:52" 1192 }]);1193 assert.dateFormat( date, "OOOO", cldr, [{1194 type: "zone",1195 value: "GMT-07:52" 1196 }]);1197 date = new FakeDate( 5.5 );1198 assert.dateFormat( date, "O", cldr, [{1199 type: "zone",1200 value: "GMT+5:30" 1201 }]);1202 assert.dateFormat( date, "OOOO", cldr, [{1203 type: "zone",1204 value: "GMT+05:30"1205 }]);1206});1207QUnit.test( "should format timezone (v)", function( assert ) {1208 var date = new Date( 2017, 5, 1 );1209 assert.dateFormatWithTimezone( date, "v", "America/Los_Angeles", cldr, [{1210 type: "zone",1211 value: "PT"1212 }]);1213 assert.dateFormatWithTimezone( date, "vvvv", "America/Los_Angeles", cldr, [{1214 type: "zone",1215 value: "Pacific Time"1216 }]);1217 // Use metazone.1218 assert.dateFormatWithTimezone( date, "vvvv", "America/Sao_Paulo", cldr, [{1219 type: "zone",1220 value: "Brasilia Time"1221 }]);1222 // Fall through 'VVVV' format.1223 assert.dateFormatWithTimezone( date, "v", "America/Sao_Paulo", cldr, [{1224 type: "zone",1225 value: "Sao Paulo Time"1226 }]);1227 assert.dateFormatWithTimezone( date, "v", "Foo/Baz", cldr, [{1228 type: "zone",1229 value: "Foo City Time"1230 }]);1231 assert.dateFormatWithTimezone( date, "vvvv", "Foo/Baz", cldr, [{1232 type: "zone",1233 value: "Foo City Time"1234 }]);1235 // Fall through 'O' and 'OOOO' formats.1236 assert.dateFormatWithTimezone( date, "v", "Etc/GMT+8", cldr, [{1237 type: "zone",1238 value: "GMT-8"1239 }]);1240 assert.dateFormatWithTimezone( date, "vvvv", "Etc/GMT+8", cldr, [{1241 type: "zone",1242 value: "GMT-08:00"1243 }]);1244});1245QUnit.test( "should format timezone (V)", function( assert ) {1246 var date = new Date( 2017, 5, 1 );1247 assert.dateFormatWithTimezone( date, "VV", "America/Los_Angeles", cldr, [{1248 type: "zone",1249 value: "America/Los_Angeles"1250 }]);1251 assert.dateFormatWithTimezone( date, "VVV", "America/Los_Angeles", cldr, [{1252 type: "zone",1253 value: "Los Angeles"1254 }]);1255 assert.dateFormatWithTimezone( date, "VVVV", "America/Los_Angeles", cldr, [{1256 type: "zone",1257 value: "Los Angeles Time"1258 }]);1259 assert.dateFormatWithTimezone( date, "VVVV", "America/Sao_Paulo", cldr, [{1260 type: "zone",1261 value: "Sao Paulo Time"1262 }]);1263 // Fall through 'VVV' format with "Unknown" exemplarCity.1264 assert.dateFormatWithTimezone( date, "VVV", "Foo/Bar", cldr, [{1265 type: "zone",1266 value: "Unknown City"1267 }]);1268 // Fall through 'OOOO' format.1269 assert.dateFormatWithTimezone( date, "VVVV", "Etc/GMT+8", cldr, [{1270 type: "zone",1271 value: "GMT-08:00"1272 }]);1273});1274QUnit.test( "should format timezone (X)", function( assert ) {1275 var date = new FakeDate( 0 );1276 assert.dateFormat( date, "X", cldr, [{1277 type: "zone",1278 value: "Z"1279 }]);1280 assert.dateFormat( date, "XX", cldr, [{1281 type: "zone",1282 value: "Z"1283 }]);1284 assert.dateFormat( date, "XXX", cldr, [{1285 type: "zone",1286 value: "Z"1287 }]);1288 assert.dateFormat( date, "XXXX", cldr, [{1289 type: "zone",1290 value: "Z"1291 }]);1292 assert.dateFormat( date, "XXXXX", cldr, [{1293 type: "zone",1294 value: "Z"1295 }]);1296 date = new FakeDate( -3 );1297 assert.dateFormat( date, "X", cldr, [{1298 type: "zone",1299 value: "-03"1300 }]);1301 assert.dateFormat( date, "XX", cldr, [{1302 type: "zone",1303 value: "-0300"1304 }]);1305 assert.dateFormat( date, "XXX", cldr, [{1306 type: "zone",1307 value: "-03:00"1308 }]);1309 assert.dateFormat( date, "XXXX", cldr, [{1310 type: "zone",1311 value: "-0300"1312 }]);1313 assert.dateFormat( date, "XXXXX", cldr, [{1314 type: "zone",1315 value: "-03:00"1316 }]);1317 date = new FakeDate( -7.883 );1318 assert.dateFormat( date, "X", cldr, [{1319 type: "zone",1320 value: "-0752" 1321 }]);1322 assert.dateFormat( date, "XX", cldr, [{1323 type: "zone",1324 value: "-0752" 1325 }]);1326 assert.dateFormat( date, "XXX", cldr, [{1327 type: "zone",1328 value: "-07:52" 1329 }]);1330 assert.dateFormat( date, "XXXX", cldr, [{1331 type: "zone",1332 value: "-075258" 1333 }]);1334 assert.dateFormat( date, "XXXXX", cldr, [{1335 type: "zone",1336 value: "-07:52:58" 1337 }]);1338 date = new FakeDate( 5.5 );1339 assert.dateFormat( date, "X", cldr, [{1340 type: "zone",1341 value: "+0530" 1342 }]);1343 assert.dateFormat( date, "XX", cldr, [{1344 type: "zone",1345 value: "+0530"1346 }]);1347 assert.dateFormat( date, "XXX", cldr, [{1348 type: "zone",1349 value: "+05:30"1350 }]);1351 assert.dateFormat( date, "XXXX", cldr, [{1352 type: "zone",1353 value: "+0530"1354 }]);1355 assert.dateFormat( date, "XXXXX", cldr, [{1356 type: "zone",1357 value: "+05:30"1358 }]);1359 date = new FakeDate( 11 );1360 assert.dateFormat( date, "X", cldr, [{1361 type: "zone",1362 value: "+11"1363 }]);1364 assert.dateFormat( date, "XX", cldr, [{1365 type: "zone",1366 value: "+1100"1367 }]);1368 assert.dateFormat( date, "XXX", cldr, [{1369 type: "zone",1370 value: "+11:00"1371 }]);1372 assert.dateFormat( date, "XXXX", cldr, [{1373 type: "zone",1374 value: "+1100"1375 }]);1376 assert.dateFormat( date, "XXXXX", cldr, [{1377 type: "zone",1378 value: "+11:00"1379 }]);1380});1381QUnit.test( "should format timezone (x)", function( assert ) {1382 var date = new FakeDate( 0 );1383 assert.dateFormat( date, "x", cldr, [{1384 type: "zone",1385 value: "+00"1386 }]);1387 assert.dateFormat( date, "xx", cldr, [{1388 type: "zone",1389 value: "+0000"1390 }]);1391 assert.dateFormat( date, "xxx", cldr, [{1392 type: "zone",1393 value: "+00:00"1394 }]);1395 assert.dateFormat( date, "xxxx", cldr, [{1396 type: "zone",1397 value: "+0000"1398 }]);1399 assert.dateFormat( date, "xxxxx", cldr, [{1400 type: "zone",1401 value: "+00:00"1402 }]);1403 date = new FakeDate( -3 );1404 assert.dateFormat( date, "x", cldr, [{1405 type: "zone",1406 value: "-03"1407 }]);1408 assert.dateFormat( date, "xx", cldr, [{1409 type: "zone",1410 value: "-0300"1411 }]);1412 assert.dateFormat( date, "xxx", cldr, [{1413 type: "zone",1414 value: "-03:00"1415 }]);1416 assert.dateFormat( date, "xxxx", cldr, [{1417 type: "zone",1418 value: "-0300"1419 }]);1420 assert.dateFormat( date, "xxxxx", cldr, [{1421 type: "zone",1422 value: "-03:00"1423 }]);1424 date = new FakeDate( -7.883 );1425 assert.dateFormat( date, "x", cldr, [{1426 type: "zone",1427 value: "-0752" 1428 }]);1429 assert.dateFormat( date, "xx", cldr, [{1430 type: "zone",1431 value: "-0752" 1432 }]);1433 assert.dateFormat( date, "xxx", cldr, [{1434 type: "zone",1435 value: "-07:52" 1436 }]);1437 assert.dateFormat( date, "xxxx", cldr, [{1438 type: "zone",1439 value: "-075258" 1440 }]);1441 assert.dateFormat( date, "xxxxx", cldr, [{1442 type: "zone",1443 value: "-07:52:58" 1444 }]);1445 date = new FakeDate( 5.5 );1446 assert.dateFormat( date, "x", cldr, [{1447 type: "zone",1448 value: "+0530" 1449 }]);1450 assert.dateFormat( date, "xx", cldr, [{1451 type: "zone",1452 value: "+0530"1453 }]);1454 assert.dateFormat( date, "xxx", cldr, [{1455 type: "zone",1456 value: "+05:30"1457 }]);1458 assert.dateFormat( date, "xxxx", cldr, [{1459 type: "zone",1460 value: "+0530"1461 }]);1462 assert.dateFormat( date, "xxxxx", cldr, [{1463 type: "zone",1464 value: "+05:30"1465 }]);1466 date = new FakeDate( 11 );1467 assert.dateFormat( date, "x", cldr, [{1468 type: "zone",1469 value: "+11"1470 }]);1471 assert.dateFormat( date, "xx", cldr, [{1472 type: "zone",1473 value: "+1100"1474 }]);1475 assert.dateFormat( date, "xxx", cldr, [{1476 type: "zone",1477 value: "+11:00"1478 }]);1479 assert.dateFormat( date, "xxxx", cldr, [{1480 type: "zone",1481 value: "+1100"1482 }]);1483 assert.dateFormat( date, "xxxxx", cldr, [{1484 type: "zone",1485 value: "+11:00"1486 }]);1487});1488/**1489 * Literal1490 */1491QUnit.test( "should format literal (')", function( assert ) {1492 assert.dateFormat( date1, "yyyy.MM.dd G 'at' HH:mm:ss", cldr, [1493 {1494 "type": "year",1495 "value": "1982"1496 },1497 {1498 "type": "literal",1499 "value": "."1500 },1501 {1502 "type": "month",1503 "value": "01"1504 },1505 {1506 "type": "literal",1507 "value": "."1508 },1509 {1510 "type": "day",1511 "value": "02"1512 },1513 {1514 "type": "literal",1515 "value": " "1516 },1517 {1518 "type": "era",1519 "value": "AD"1520 },1521 {1522 "type": "literal",1523 "value": " at "1524 },1525 {1526 "type": "hour",1527 "value": "09"1528 },1529 {1530 "type": "literal",1531 "value": ":"1532 },1533 {1534 "type": "minute",1535 "value": "05"1536 },1537 {1538 "type": "literal",1539 "value": ":"1540 },1541 {1542 "type": "second",1543 "value": "59"1544 }1545 ]);1546 assert.dateFormat( date1, "hh 'o''clock' a", cldr, [1547 {1548 "type": "hour",1549 "value": "09"1550 },1551 {1552 "type": "literal",1553 "value": " o'clock "1554 },1555 {1556 "type": "dayperiod",1557 "value": "AM"1558 }1559 ]);1560});...
locale.js
Source:locale.js
1/******************************************************************************2 * Copyright © 2013-2016 The Nxt Core Developers. *3 * Copyright © 2016 Jelurida IP B.V. *4 * *5 * See the LICENSE.txt file at the top-level directory of this distribution *6 * for licensing information. *7 * *8 * Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,*9 * no part of the Nxt software, including this file, may be copied, modified, *10 * propagated, or distributed except according to the terms contained in the *11 * LICENSE.txt file. *12 * *13 * Removal or modification of this copyright notice is prohibited. *14 * *15 ******************************************************************************/16var NRS = (function (NRS) {17 var currentLocale = {};18 NRS.getLocaleList = function() {19 return SORTED_LOCALE_DATE;20 };21 22 NRS.getLocaleName = function(locale) {23 return LOCALE_DATA[locale].displayName;24 };25 NRS.getLocale = function () {26 var lang;27 if (NRS.settings && NRS.settings['regional_format'] != "default") {28 lang = NRS.settings['regional_format'];29 } else {30 lang = window.javaFxLanguage || window.navigator.userLanguage || window.navigator.language;31 if (!LOCALE_DATA[lang]) {32 if (lang && lang.length == 2) {33 // Attempt to expand the Chrome two letter language to country specific locale34 if (window.navigator.languages) {35 var tokens = String(window.navigator.languages).split(",");36 for (var i=0; i<tokens.length; i++) {37 var separator = tokens[i].indexOf("-");38 if (separator == -1) {39 continue;40 }41 if (tokens[i].substring(0, separator) == lang) {42 NRS.logConsole("Language " + lang + " resolved to locale " + tokens[i]);43 lang = tokens[i];44 break;45 }46 }47 }48 }49 if (!LOCALE_DATA[lang]) {50 if (!currentLocale.lang) {51 NRS.logConsole("Cannot find locale definitions for language " + lang + " default to en-US");52 }53 lang = "en-US";54 }55 }56 }57 if (!currentLocale.lang || currentLocale.lang != lang) {58 currentLocale = {};59 currentLocale.lang = lang;60 currentLocale.dateFormat = LOCALE_DATA[lang].dateFormat;61 currentLocale.decimal = LOCALE_DATA[lang].decimal;62 currentLocale.section = LOCALE_DATA[lang].section;63 currentLocale.displayName = LOCALE_DATA[lang].displayName;64 NRS.logConsole("Locale language: '" + currentLocale.lang +65 "' date format: '" + currentLocale.dateFormat +66 "' decimal separator: '" + currentLocale.decimal +67 "' section separator: '" + currentLocale.section +68 "' display name: '" + currentLocale.displayName + "'");69 }70 return currentLocale;71 };72 var LOCALE_DATA = {73 "af-ZA": {dateFormat: "yyyy/MM/dd", decimal: ".", section: ",", displayName: "Afrikaans (South Africa)"},74 "am-ET": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Amharic (Ethiopia)"},75 "ar-AE": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (United Arab Emirates)"},76 "ar-BH": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Bahrain)"},77 "ar-DZ": {dateFormat: "dd-MM-yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Algeria)"},78 "ar-EG": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Egypt)"},79 "ar-IQ": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Iraq)"},80 "ar-JO": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Jordan)"},81 "ar-KW": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Kuwait)"},82 "ar-LB": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Lebanon)"},83 "ar-LY": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Libya)"},84 "ar-MA": {dateFormat: "dd-MM-yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Morocco)"},85 "arn-CL": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Mapudungun (Chile)"},86 "ar-OM": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Oman)"},87 "ar-QA": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Qatar)"},88 "ar-SA": {dateFormat: "dd/MM/yy", decimal: "٫", section: "٬", displayName: "Arabic (Saudi Arabia)"},89 "ar-SY": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Syria)"},90 "ar-TN": {dateFormat: "dd-MM-yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Tunisia)"},91 "ar-YE": {dateFormat: "dd/MM/yyyy", decimal: "٫", section: "٬", displayName: "Arabic (Yemen)"},92 "as-IN": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Assamese (India)"},93 "az-Cyrl-AZ": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Azerbaijani (CYRL,AZ)"},94 "az-Latn-AZ": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Azerbaijani (LATN,AZ)"},95 "ba-RU": {dateFormat: "dd.MM.yy", decimal: ",", section: " ", displayName: "Bashkir (Russia)"},96 "be-BY": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Belarusian (Belarus)"},97 "bg-BG": {dateFormat: "dd.M.yyyy", decimal: ",", section: " ", displayName: "Bulgarian (Bulgaria)"},98 "bn-BD": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Bengali (Bangladesh)"},99 "bn-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Bengali (India)"},100 "bo-CN": {dateFormat: "yyyy/M/d", decimal: ",", section: " ", displayName: "Tibetan (China)"},101 "br-FR": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Breton (France)"},102 "bs-Cyrl-BA": {dateFormat: "d.M.yyyy", decimal: ".", section: ",", displayName: "Bosnian (CYRL,BA)"},103 "bs-Latn-BA": {dateFormat: "d.M.yyyy", decimal: ".", section: ",", displayName: "Bosnian (LATN,BA)"},104 "ca-ES": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Catalan (Spain)"},105 "co-FR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Corsican (France)"},106 "cs-CZ": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Czech (Czech Republic)"},107 "cy-GB": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Welsh (United Kingdom)"},108 "da-DK": {dateFormat: "dd-MM-yyyy", decimal: ",", section: ".", displayName: "Danish (Denmark)"},109 "de-AT": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "German (Austria)"},110 "de-CH": {dateFormat: "dd.MM.yyyy", decimal: ".", section: "'", displayName: "German (Switzerland)"},111 "de-DE": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "German (Germany)"},112 "de-LI": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "German (Liechtenstein)"},113 "de-LU": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "German (Luxembourg)"},114 "dsb-DE": {dateFormat: "d. M. yyyy", decimal: ",", section: " ", displayName: "Lower Sorbian (Germany)"},115 "dv-MV": {dateFormat: "dd/MM/yy", decimal: ",", section: " ", displayName: "Divehi (Maldives)"},116 "el-GR": {dateFormat: "d/M/yyyy", decimal: ",", section: ".", displayName: "Greek (Greece)"},117 "en-029": {dateFormat: "MM/dd/yyyy", decimal: ".", section: ",", displayName: "English (Caribbean)"},118 "en-AU": {dateFormat: "d/MM/yyyy", decimal: ".", section: ",", displayName: "English (Australia)"},119 "en-BZ": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (Belize)"},120 "en-CA": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (Canada)"},121 "en-GB": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (United Kingdom)"},122 "en-IE": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (Ireland)"},123 "en-IN": {dateFormat: "dd-MM-yyyy", decimal: ".", section: ",", displayName: "English (India)"},124 "en-JM": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (Jamaica)"},125 "en-MY": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "English (Malaysia)"},126 "en-NZ": {dateFormat: "d/MM/yyyy", decimal: ".", section: ",", displayName: "English (New Zealand)"},127 "en-PH": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "English (Philippines)"},128 "en-SG": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "English (Singapore)"},129 "en-TT": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "English (Trinidad and Tobago)"},130 "en-US": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "English (United States)"},131 "en-ZA": {dateFormat: "yyyy/MM/dd", decimal: ",", section: " ", displayName: "English (South Africa)"},132 "en-ZW": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "English (Zimbabwe)"},133 "es-AR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Argentina)"},134 "es-BO": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Bolivia)"},135 "es-CL": {dateFormat: "dd-MM-yyyy", decimal: ",", section: ".", displayName: "Spanish (Chile)"},136 "es-CO": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Colombia)"},137 "es-CR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Costa Rica)"},138 "es-DO": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Dominican Republic)"},139 "es-EC": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Ecuador)"},140 "es-ES": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Spain)"},141 "es-GT": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Guatemala)"},142 "es-HN": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Honduras)"},143 "es-MX": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Spanish (Mexico)"},144 "es-NI": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Nicaragua)"},145 "es-PA": {dateFormat: "MM/dd/yyyy", decimal: ",", section: ".", displayName: "Spanish (Panama)"},146 "es-PE": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Peru)"},147 "es-PR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Puerto Rico)"},148 "es-PY": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Paraguay)"},149 "es-SV": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (El Salvador)"},150 "es-US": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "Spanish (United States)"},151 "es-UY": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Uruguay)"},152 "es-VE": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Spanish (Venezuela)"},153 "et-EE": {dateFormat: "d.MM.yyyy", decimal: ",", section: " ", displayName: "Estonian (Estonia)"},154 "eu-ES": {dateFormat: "yyyy/MM/dd", decimal: ".", section: ",", displayName: "Basque (Spain)"},155 "fa-IR": {dateFormat: "MM/dd/yyyy", decimal: "٫", section: "٬", displayName: "Persian (Iran)"},156 "fi-FI": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Finnish (Finland)"},157 "fil-PH": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "Filipino (Philippines)"},158 "fo-FO": {dateFormat: "dd-MM-yyyy", decimal: ".", section: ",", displayName: "Faroese (Faroe Islands)"},159 "fr-BE": {dateFormat: "d/MM/yyyy", decimal: ",", section: " ", displayName: "French (Belgium)"},160 "fr-CA": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "French (Canada)"},161 "fr-CH": {dateFormat: "dd.MM.yyyy", decimal: ".", section: " ", displayName: "French (Switzerland)"},162 "fr-FR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "French (France)"},163 "fr-LU": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "French (Luxembourg)"},164 "fr-MC": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "French (Monaco)"},165 "fy-NL": {dateFormat: "d-M-yyyy", decimal: ",", section: " ", displayName: "Frisian (Netherlands)"},166 "ga-IE": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Irish (Ireland)"},167 "gd-GB": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Scottish Gaelic (United Kingdom)"},168 "gl-ES": {dateFormat: "dd/MM/yy", decimal: ".", section: ",", displayName: "Gallegan (Spain)"},169 "gsw-FR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Swiss German (France)"},170 "gu-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Gujarati (India)"},171 "ha-Latn-NG": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Hausa (LATN,NG)"},172 "he-IL": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Hebrew (Israel)"},173 "hi-IN": {dateFormat: "dd-MM-yyyy", decimal: ".", section: ",", displayName: "Hindi (India)"},174 "hr-BA": {dateFormat: "d.M.yyyy.", decimal: ",", section: ".", displayName: "Croatian (Bosnia and Herzegovina)"},175 "hr-HR": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Croatian (Croatia)"},176 "hsb-DE": {dateFormat: "d. M. yyyy", decimal: ",", section: " ", displayName: "Upper Sorbian (Germany)"},177 "hu-HU": {dateFormat: "yyyy. MM. dd.", decimal: ",", section: " ", displayName: "Hungarian (Hungary)"},178 "hy-AM": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Armenian (Armenia)"},179 "id-ID": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Indonesian (Indonesia)"},180 "ig-NG": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Igbo (Nigeria)"},181 "ii-CN": {dateFormat: "yyyy/M/d", decimal: ",", section: " ", displayName: "Sichuan Yi (China)"},182 "is-IS": {dateFormat: "d.M.yyyy", decimal: ".", section: ",", displayName: "Icelandic (Iceland)"},183 "it-CH": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "Italian (Switzerland)"},184 "it-IT": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Italian (Italy)"},185 "iu-Cans-CA": {dateFormat: "d/M/yyyy", decimal: ",", section: " ", displayName: "Inuktitut (CANS,CA)"},186 "iu-Latn-CA": {dateFormat: "d/MM/yyyy", decimal: ",", section: " ", displayName: "Inuktitut (LATN,CA)"},187 "ja-JP": {dateFormat: "yyyy/MM/dd", decimal: ".", section: ",", displayName: "Japanese (Japan)"},188 "ka-GE": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Georgian (Georgia)"},189 "kk-KZ": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Kazakh (Kazakhstan)"},190 "kl-GL": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Greenlandic (Greenland)"},191 "km-KH": {dateFormat: "yyyy-MM-dd", decimal: ".", section: ",", displayName: "Khmer (Cambodia)"},192 "kn-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Kannada (India)"},193 "kok-IN": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Konkani (India)"},194 "ko-KR": {dateFormat: "yyyy-MM-dd", decimal: ".", section: ",", displayName: "Korean (South Korea)"},195 "ky-KG": {dateFormat: "dd.MM.yy", decimal: ".", section: ",", displayName: "Kirghiz (Kyrgyzstan)"},196 "lb-LU": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Luxembourgish (Luxembourg)"},197 "lo-LA": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Lao (Laos)"},198 "lt-LT": {dateFormat: "yyyy.MM.dd", decimal: ",", section: " ", displayName: "Lithuanian (Lithuania)"},199 "lv-LV": {dateFormat: "yyyy.MM.dd.", decimal: ",", section: " ", displayName: "Latvian (Latvia)"},200 "mi-NZ": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Maori (New Zealand)"},201 "mk-MK": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Macedonian (Macedonia)"},202 "ml-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Malayalam (India)"},203 "mn-MN": {dateFormat: "yy.MM.dd", decimal: ".", section: ",", displayName: "Mongolian (Mongolia)"},204 "mn-Mong-CN": {dateFormat: "yyyy/M/d", decimal: ".", section: ",", displayName: "Mongolian (MONG,CN)"},205 "moh-CA": {dateFormat: "M/d/yyyy", decimal: ",", section: " ", displayName: "Mohawk (Canada)"},206 "mr-IN": {dateFormat: "dd-MM-yyyy", decimal: ".", section: ",", displayName: "Marathi (India)"},207 "ms-BN": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Malay (Brunei)"},208 "ms-MY": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Malay (Malaysia)"},209 "mt-MT": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Maltese (Malta)"},210 "nb-NO": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Norwegian Bokmål (Norway)"},211 "ne-NP": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "Nepali (Nepal)"},212 "nl-BE": {dateFormat: "d/MM/yyyy", decimal: ",", section: ".", displayName: "Dutch (Belgium)"},213 "nl-NL": {dateFormat: "d-M-yyyy", decimal: ",", section: ".", displayName: "Dutch (Netherlands)"},214 "nn-NO": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Norwegian Nynorsk (Norway)"},215 "nso-ZA": {dateFormat: "yyyy/MM/dd", decimal: ",", section: " ", displayName: "Pedi (South Africa)"},216 "oc-FR": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Occitan (France)"},217 "or-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Oriya (India)"},218 "pa-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Panjabi (India)"},219 "pl-PL": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "Polish (Poland)"},220 "prs-AF": {dateFormat: "dd/MM/yy", decimal: ",", section: " ", displayName: "prs (Afghanistan)"},221 "ps-AF": {dateFormat: "dd/MM/yy", decimal: ".", section: ",", displayName: "Pushto (Afghanistan)"},222 "pt-BR": {dateFormat: "d/M/yyyy", decimal: ",", section: ".", displayName: "Portuguese (Brazil)"},223 "pt-PT": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Portuguese (Portugal)"},224 "qut-GT": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "qut (Guatemala)"},225 "quz-BO": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "quz (Bolivia)"},226 "quz-EC": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "quz (Ecuador)"},227 "quz-PE": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "quz (Peru)"},228 "rm-CH": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Raeto-Romance (Switzerland)"},229 "ro-RO": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "Romanian (Romania)"},230 "ru-RU": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Russian (Russia)"},231 "rw-RW": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "Kinyarwanda (Rwanda)"},232 "sah-RU": {dateFormat: "MM.dd.yyyy", decimal: ",", section: " ", displayName: "Yakut (Russia)"},233 "sa-IN": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "Sanskrit (India)"},234 "se-FI": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Northern Sami (Finland)"},235 "se-NO": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Northern Sami (Norway)"},236 "se-SE": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "Northern Sami (Sweden)"},237 "si-LK": {dateFormat: "yyyy-MM-dd", decimal: ".", section: ",", displayName: "Sinhalese (Sri Lanka)"},238 "sk-SK": {dateFormat: "d. M. yyyy", decimal: ",", section: " ", displayName: "Slovak (Slovakia)"},239 "sl-SI": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Slovenian (Slovenia)"},240 "sma-NO": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Southern Sami (Norway)"},241 "sma-SE": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "Southern Sami (Sweden)"},242 "smj-NO": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Lule Sami (Norway)"},243 "smj-SE": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "Lule Sami (Sweden)"},244 "smn-FI": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Inari Sami (Finland)"},245 "sms-FI": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Skolt Sami (Finland)"},246 "sq-AL": {dateFormat: "yyyy-MM-dd", decimal: ".", section: ",", displayName: "Albanian (Albania)"},247 "sr-Cyrl-BA": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (CYRL,BA)"},248 "sr-Cyrl-CS": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (CYRL,CS)"},249 "sr-Cyrl-ME": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (CYRL,ME)"},250 "sr-Cyrl-RS": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (CYRL,RS)"},251 "sr-Latn-BA": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (LATN,BA)"},252 "sr-Latn-CS": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (LATN,CS)"},253 "sr-Latn-ME": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (LATN,ME)"},254 "sr-Latn-RS": {dateFormat: "d.M.yyyy", decimal: ",", section: ".", displayName: "Serbian (LATN,RS)"},255 "sv-FI": {dateFormat: "d.M.yyyy", decimal: ",", section: " ", displayName: "Swedish (Finland)"},256 "sv-SE": {dateFormat: "yyyy-MM-dd", decimal: ",", section: " ", displayName: "Swedish (Sweden)"},257 "sw-KE": {dateFormat: "M/d/yyyy", decimal: ".", section: ",", displayName: "Swahili (Kenya)"},258 "syr-SY": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Syriac (Syria)"},259 "ta-IN": {dateFormat: "dd-MM-yyyy", decimal: ".", section: ",", displayName: "Tamil (India)"},260 "te-IN": {dateFormat: "dd-MM-yy", decimal: ".", section: ",", displayName: "Telugu (India)"},261 "tg-Cyrl-TJ": {dateFormat: "dd.MM.yy", decimal: ".", section: ",", displayName: "Tajik (CYRL,TJ)"},262 "th-TH": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Thai (Thailand)"},263 "tk-TM": {dateFormat: "dd.MM.yy", decimal: ",", section: " ", displayName: "Turkmen (Turkmenistan)"},264 "tn-ZA": {dateFormat: "yyyy/MM/dd", decimal: ",", section: " ", displayName: "Tswana (South Africa)"},265 "tr-TR": {dateFormat: "dd.MM.yyyy", decimal: ",", section: ".", displayName: "Turkish (Turkey)"},266 "tt-RU": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Tatar (Russia)"},267 "tzm-Latn-DZ": {dateFormat: "dd-MM-yyyy", decimal: ",", section: " ", displayName: "tzm (LATN,DZ)"},268 "ug-CN": {dateFormat: "yyyy-M-d", decimal: ",", section: " ", displayName: "Uighur (China)"},269 "uk-UA": {dateFormat: "dd.MM.yyyy", decimal: ",", section: " ", displayName: "Ukrainian (Ukraine)"},270 "ur-PK": {dateFormat: "dd/MM/yyyy", decimal: ".", section: ",", displayName: "Urdu (Pakistan)"},271 "uz-Cyrl-UZ": {dateFormat: "dd.MM.yyyy", decimal: ".", section: ",", displayName: "Uzbek (CYRL,UZ)"},272 "uz-Latn-UZ": {dateFormat: "dd/MM yyyy", decimal: ".", section: ",", displayName: "Uzbek (LATN,UZ)"},273 "vi-VN": {dateFormat: "dd/MM/yyyy", decimal: ",", section: ".", displayName: "Vietnamese (Vietnam)"},274 "wo-SN": {dateFormat: "dd/MM/yyyy", decimal: ",", section: " ", displayName: "Wolof (Senegal)"},275 "xh-ZA": {dateFormat: "yyyy/MM/dd", decimal: ",", section: " ", displayName: "Xhosa (South Africa)"},276 "yo-NG": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Yoruba (Nigeria)"},277 "zh-CN": {dateFormat: "yyyy/M/d", decimal: ".", section: ",", displayName: "Chinese (China)"},278 "zh-HK": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Chinese (Hong Kong)"},279 "zh-MO": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Chinese (Macao)"},280 "zh-SG": {dateFormat: "d/M/yyyy", decimal: ".", section: ",", displayName: "Chinese (Singapore)"},281 "zh-TW": {dateFormat: "yyyy/M/d", decimal: ".", section: ",", displayName: "Chinese (Taiwan)"},282 "zu-ZA": {dateFormat: "yyyy/MM/dd", decimal: ".", section: ",", displayName: "Zulu (South Africa)"}283 };284 var SORTED_LOCALE_DATE = Object.keys(LOCALE_DATA).sort(function(a,b) {285 return LOCALE_DATA[a].displayName.localeCompare(LOCALE_DATA[b].displayName);286 });287 return NRS;...
other.ts
Source:other.ts
1import * as DateFns from 'date-fns';2import {enUS, ru} from 'date-fns/locale';3export default class DateFormat {4 static LOCALE = process.env.NEXT_PUBLIC_LOCALE === 'en' ? enUS : ru;5 static FORMATS = {6 default: 'dd.MM.yyyy',7 fullMonth: 'dd MMMM yyyy',8 };9 static today = (): DateFormat => {10 const dateFormat = new DateFormat();11 dateFormat.date = new Date();12 return dateFormat;13 };14 static fromISO = (iso: string): DateFormat => {15 const dateFormat = new DateFormat();16 dateFormat.fromISO(iso);17 return dateFormat;18 };19 static fromDate = (date: Date): DateFormat => {20 const dateFormat = new DateFormat();21 dateFormat.fromDate(date);22 return dateFormat;23 };24 static min = (dateFormats: Array<DateFormat | undefined>): DateFormat | undefined => {25 let min: DateFormat | undefined;26 dateFormats.forEach(dateFormat => {27 if (dateFormat?.date === undefined) return;28 if (min === undefined || (min.date !== undefined && dateFormat.date < min.date))29 min = dateFormat;30 });31 return min;32 };33 static max = (dateFormats: Array<DateFormat | undefined>): DateFormat | undefined => {34 let max: DateFormat | undefined;35 dateFormats.forEach(dateFormat => {36 if (dateFormat?.date === undefined) return;37 if (max === undefined || (max.date !== undefined && dateFormat.date > max.date))38 max = dateFormat;39 });40 return max;41 };42 static differenceInDays = (43 a: DateFormat | undefined,44 b: DateFormat | undefined45 ): number | undefined => {46 if (!a?.date || !b?.date) return;47 return DateFns.differenceInDays(a.date, b.date);48 };49 date: Date | undefined;50 fromISO = (iso: string): void => {51 this.date = DateFns.parseISO(iso);52 };53 fromDate = (date: Date): void => {54 this.date = date;55 };56 isBefore = (dateFormat: DateFormat | undefined): boolean | undefined => {57 if (dateFormat?.date === undefined) return;58 if (this.date === undefined) return;59 return DateFns.isBefore(this.date, dateFormat.date);60 };61 isAfter = (dateFormat: DateFormat | undefined): boolean | undefined => {62 if (dateFormat?.date === undefined) return;63 if (this.date === undefined) return;64 return DateFns.isAfter(this.date, dateFormat.date);65 };66 isPast = (): boolean | undefined => {67 if (this.date === undefined) return;68 return DateFns.isPast(this.date);69 };70 isFuture = (): boolean | undefined => {71 if (this.date === undefined) return;72 return DateFns.isFuture(this.date);73 };74 toString = (): string | undefined => {75 return this.default;76 };77 addDays = (days: number): DateFormat | undefined => {78 if (this.date === undefined) return;79 const dateFormat = new DateFormat();80 dateFormat.date = DateFns.addDays(this.date, days);81 return dateFormat;82 };83 addMonths = (months: number): DateFormat | undefined => {84 if (this.date === undefined) return;85 const dateFormat = new DateFormat();86 dateFormat.date = DateFns.addMonths(this.date, months);87 return dateFormat;88 };89 isSameMonth = (dateFormat: DateFormat | undefined): boolean | undefined => {90 if (this.date === undefined || dateFormat?.date === undefined) return;91 return DateFns.isSameMonth(this.date, dateFormat.date);92 };93 isSameYear = (dateFormat: DateFormat | undefined): boolean | undefined => {94 if (this.date === undefined || dateFormat?.date === undefined) return;95 return DateFns.isSameYear(this.date, dateFormat.date);96 };97 startOfMonth = (): DateFormat | undefined => {98 if (this.date === undefined) return;99 const dateFormat = new DateFormat();100 dateFormat.date = DateFns.startOfMonth(this.date);101 return dateFormat;102 };103 endOfMonth = (): DateFormat | undefined => {104 if (this.date === undefined) return;105 const dateFormat = new DateFormat();106 dateFormat.date = DateFns.endOfMonth(this.date);107 return dateFormat;108 };109 getDaysInMonth = (): number | undefined => {110 if (this.date === undefined) return;111 return DateFns.getDaysInMonth(this.date);112 };113 getDaysInYear = (): number | undefined => {114 if (this.date === undefined) return;115 return DateFns.getDaysInYear(this.date);116 };117 get default(): string | undefined {118 return this.format(DateFormat.FORMATS.default);119 }120 format = (format = DateFormat.FORMATS.default): string | undefined => {121 if (!this.date) return;122 return DateFns.format(this.date, format, {locale: DateFormat.LOCALE});123 };...
Using AI Code Generation
1var dateFormat = require('dateformat');2var now = new Date();3console.log(dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT"));4var dateFormat = require('dateformat');5var now = new Date();6console.log(dateFormat(now, "h:MM:ss TT"));
Using AI Code Generation
1var BestDate = require('best-date');2console.log(BestDate.dateFormat('yyyy-MM-dd'));3var BestDate = require('best-date');4console.log(BestDate.dateFormat('yyyy-MM-dd'));5var BestDate = require('best-date');6console.log(BestDate.dateFormat('yyyy-MM-dd'));7var BestDate = require('best-date');8console.log(BestDate.dateFormat('yyyy-MM-dd'));9var BestDate = require('best-date');10console.log(BestDate.dateFormat('yyyy-MM-dd'));11var BestDate = require('best-date');12console.log(BestDate.dateFormat('yyyy-MM-dd'));13var BestDate = require('best-date');14console.log(BestDate.dateFormat('yyyy-MM-dd'));15var BestDate = require('best-date');16console.log(BestDate.dateFormat('yyyy-MM-dd'));17var BestDate = require('best-date');18console.log(BestDate.dateFormat('yyyy-MM-dd'));19var BestDate = require('best-date');20console.log(BestDate.dateFormat('yyyy-MM-dd'));21var BestDate = require('best-date');22console.log(BestDate.dateFormat('yyyy-MM-dd'));23var BestDate = require('best-date');24console.log(BestDate.dateFormat('yyyy-MM-dd'));25var BestDate = require('best-date');26console.log(BestDate.dateFormat('yyyy-MM-dd'));
Using AI Code Generation
1var bestTime = require('best-time');2var date = new Date();3var dateFormat = bestTime.dateFormat(date, "yyyy-mm-dd");4var bestTime = require('bestTime');5var date = new Date();6var timeFormat = bestTime.timeFormat(date, "hh:mm:ss");7var bestTime = require('bestTime');8var date = new Date();9var dateTimeFormat = bestTime.dateTimeFormat(date, "yyyy-mm-dd hh:mm:ss");10var bestTime = require('bestTime');11var duration = bestTime.duration(1000);12var bestTime = require('bestTime');13var duration = bestTime.duration(1000, 1);14var bestTime = require('bestTime');15var duration = bestTime.duration(1000, 2);16var bestTime = require('bestTime');17var duration = bestTime.duration(1000, 3);18var bestTime = require('bestTime');19var duration = bestTime.duration(1000, 4);20var bestTime = require('bestTime');21var duration = bestTime.duration(1000, 5);22var bestTime = require('bestTime');23var duration = bestTime.duration(1000, 6);24var bestTime = require('bestTime');25var duration = bestTime.duration(1000, 7);26var bestTime = require('bestTime');27var duration = bestTime.duration(1000, 8);28var bestTime = require('bestTime');29var duration = bestTime.duration(100
Using AI Code Generation
1var BestDate = require('./bestdate');2var bd = new BestDate();3console.log(bd.dateformat('YYYY-MM-DD'));4var BestDate = function() {5 this.dateformat = function(format) {6 var date = new Date();7 var year = date.getFullYear();8 var month = date.getMonth() + 1;9 var day = date.getDate();10 return year + '-' + month + '-' + day;11 }12}13module.exports = BestDate;
Using AI Code Generation
1var bestday = require('bestday');2var date = new Date();3var format = 'YYYY-MM-DD';4var formatedDate = bestday.formatDate(date, format);5console.log(formatedDate);6[MIT](LICENSE)
Using AI Code Generation
1var BestGlobals = require('bestglobals');2var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");3var BestGlobals = require('bestglobals');4var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");5var BestGlobals = require('bestglobals');6var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");7var BestGlobals = require('bestglobals');8var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");9var BestGlobals = require('bestglobals');10var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");11var BestGlobals = require('bestglobals');12var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");13var BestGlobals = require('bestglobals');14var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");15var BestGlobals = require('bestglobals');16var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");17var BestGlobals = require('bestglobals');18var date = BestGlobals.dateformat(new Date(), "dd-MM-yyyy");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!