Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --datetime-format-to-parts | |
| 6 | |
|
Dan Ehrenberg
2016/12/16 23:40:08
Could you leave the Flags: line in until the later
jungshik at Google
2016/12/19 07:27:43
Done.
| |
| 7 var d = new Date(2016, 11, 15, 14, 10, 34); | 5 var d = new Date(2016, 11, 15, 14, 10, 34); |
| 8 var df = Intl.DateTimeFormat("ja", | 6 var df = Intl.DateTimeFormat("ja", |
| 9 {hour: 'numeric', minute: 'numeric', second: 'numeric', year: 'numeric', | 7 {hour: 'numeric', minute: 'numeric', second: 'numeric', year: 'numeric', |
| 10 month: 'numeric', day: 'numeric', timeZoneName: 'short', era: 'short'}); | 8 month: 'numeric', day: 'numeric', timeZoneName: 'short', era: 'short'}); |
| 11 | 9 |
| 12 var formattedParts = df.formatToParts(d); | 10 var formattedParts = df.formatToParts(d); |
| 13 | 11 |
| 14 var formattedReconstructedFromParts = formattedParts.map((part) => part.value) | 12 var formattedReconstructedFromParts = formattedParts.map((part) => part.value) |
| 15 .reduce((accumulated, part) => accumulated + part); | 13 .reduce((accumulated, part) => accumulated + part); |
| 16 assertEquals(df.format(d), formattedReconstructedFromParts); | 14 assertEquals(df.format(d), formattedReconstructedFromParts); |
| 17 // 西暦2016年11月15日 14:10:34 GMT-7 | 15 // 西暦2016年11月15日 14:10:34 GMT-7 |
| 18 assertEquals(["era", "year", "literal", "month", "literal", "day", "literal", | 16 assertEquals(["era", "year", "literal", "month", "literal", "day", "literal", |
| 19 "hour", "literal", "minute", "literal", "second", "literal", | 17 "hour", "literal", "minute", "literal", "second", "literal", |
| 20 "timeZoneName"], formattedParts.map((part) => part.type)); | 18 "timeZoneName"], formattedParts.map((part) => part.type)); |
| OLD | NEW |