1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 // Test if resolvedOptions() returns expected fields/values. 29 30 // Default (year, month, day) formatter. 31 var dtfDefault = Intl.DateTimeFormat('en-US'); 32 var resolved = dtfDefault.resolvedOptions(); 33 34 assertTrue(resolved.hasOwnProperty('locale')); 35 assertEquals('en-US', resolved.locale); 36 assertTrue(resolved.hasOwnProperty('numberingSystem')); 37 assertEquals('latn', resolved.numberingSystem); 38 assertTrue(resolved.hasOwnProperty('calendar')); 39 assertEquals('gregory', resolved.calendar); 40 assertTrue(resolved.hasOwnProperty('timeZone')); 41 // TODO(littledan): getDefaultTimeZone() is not available from JavaScript 42 // assertEquals(getDefaultTimeZone(), resolved.timeZone); 43 // These are in by default. 44 assertTrue(resolved.hasOwnProperty('year')); 45 assertEquals('numeric', resolved.year); 46 assertTrue(resolved.hasOwnProperty('month')); 47 assertEquals('numeric', resolved.month); 48 assertTrue(resolved.hasOwnProperty('day')); 49 assertEquals('numeric', resolved.day); 50 // These shouldn't be in by default. 51 assertFalse(resolved.hasOwnProperty('era')); 52 assertFalse(resolved.hasOwnProperty('timeZoneName')); 53 assertFalse(resolved.hasOwnProperty('weekday')); 54 assertFalse(resolved.hasOwnProperty('hour12')); 55 assertFalse(resolved.hasOwnProperty('hour')); 56 assertFalse(resolved.hasOwnProperty('minute')); 57 assertFalse(resolved.hasOwnProperty('second')); 58 59 // Time formatter. 60 var dtfTime = Intl.DateTimeFormat( 61 'sr-RS', {hour: 'numeric', minute: 'numeric', second: 'numeric'}); 62 resolved = dtfTime.resolvedOptions(); 63 64 assertTrue(resolved.hasOwnProperty('locale')); 65 assertTrue(resolved.hasOwnProperty('numberingSystem')); 66 assertTrue(resolved.hasOwnProperty('calendar')); 67 assertTrue(resolved.hasOwnProperty('timeZone')); 68 assertTrue(resolved.hasOwnProperty('hour12')); 69 assertEquals(false, resolved.hour12); 70 assertTrue(resolved.hasOwnProperty('hour')); 71 assertEquals('2-digit', resolved.hour); 72 assertTrue(resolved.hasOwnProperty('minute')); 73 assertEquals('2-digit', resolved.minute); 74 assertTrue(resolved.hasOwnProperty('second')); 75 assertEquals('2-digit', resolved.second); 76 // Didn't ask for them. 77 assertFalse(resolved.hasOwnProperty('year')); 78 assertFalse(resolved.hasOwnProperty('month')); 79 assertFalse(resolved.hasOwnProperty('day')); 80 assertFalse(resolved.hasOwnProperty('era')); 81 assertFalse(resolved.hasOwnProperty('timeZoneName')); 82 assertFalse(resolved.hasOwnProperty('weekday')); 83 84 // Full formatter. 85 var dtfFull = Intl.DateTimeFormat( 86 'en-US', {weekday: 'short', era: 'short', year: 'numeric', month: 'short', 87 day: 'numeric', hour: 'numeric', minute: 'numeric', 88 second: 'numeric', timeZoneName: 'short', timeZone: 'UTC'}); 89 resolved = dtfFull.resolvedOptions(); 90 91 assertTrue(resolved.hasOwnProperty('locale')); 92 assertTrue(resolved.hasOwnProperty('numberingSystem')); 93 assertTrue(resolved.hasOwnProperty('calendar')); 94 assertTrue(resolved.hasOwnProperty('timeZone')); 95 assertTrue(resolved.hasOwnProperty('hour12')); 96 assertEquals(true, resolved.hour12); 97 assertTrue(resolved.hasOwnProperty('hour')); 98 assertTrue(resolved.hasOwnProperty('minute')); 99 assertTrue(resolved.hasOwnProperty('second')); 100 assertTrue(resolved.hasOwnProperty('year')); 101 assertTrue(resolved.hasOwnProperty('month')); 102 assertTrue(resolved.hasOwnProperty('day')); 103 assertTrue(resolved.hasOwnProperty('era')); 104 assertEquals('short', resolved.era); 105 assertTrue(resolved.hasOwnProperty('timeZoneName')); 106 assertEquals('short', resolved.timeZoneName); 107 assertTrue(resolved.hasOwnProperty('weekday')); 108 assertEquals('short', resolved.weekday); 109