Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Side by Side Diff: src/js/i18n.js

Issue 2273953003: Add support for DateTimeFormat.formatToParts (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use readonly alias for substrings; add HandleScope to a helper function Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/runtime/runtime.h » ('j') | src/runtime/runtime-i18n.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 // ECMAScript 402 API implementation. 5 // ECMAScript 402 API implementation.
6 6
7 /** 7 /**
8 * Intl object is a single object that has some named properties, 8 * Intl object is a single object that has some named properties,
9 * all of which are constructors. 9 * all of which are constructors.
10 */ 10 */
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 } else { 1792 } else {
1793 dateMs = TO_NUMBER(dateValue); 1793 dateMs = TO_NUMBER(dateValue);
1794 } 1794 }
1795 1795
1796 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange); 1796 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1797 1797
1798 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), 1798 return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
1799 new GlobalDate(dateMs)); 1799 new GlobalDate(dateMs));
1800 } 1800 }
1801 1801
1802 function formatDateToParts(formatter, dateValue) {
1803 var dateMs;
1804 if (IS_UNDEFINED(dateValue)) {
1805 dateMs = %DateCurrentTime();
1806 } else {
1807 dateMs = TO_NUMBER(dateValue);
1808 }
1809
1810 if (!NUMBER_IS_FINITE(dateMs)) throw %make_range_error(kDateRange);
1811
1812 return %InternalDateFormatToParts(
1813 %GetImplFromInitializedIntlObject(formatter), new GlobalDate(dateMs));
1814 }
1815
1802 1816
1803 /** 1817 /**
1804 * Returns a Date object representing the result of calling ToString(value) 1818 * Returns a Date object representing the result of calling ToString(value)
1805 * according to the effective locale and the formatting options of this 1819 * according to the effective locale and the formatting options of this
1806 * DateTimeFormat. 1820 * DateTimeFormat.
1807 * Returns undefined if date string cannot be parsed. 1821 * Returns undefined if date string cannot be parsed.
1808 */ 1822 */
1809 function IntlParseDate(formatter, value) { 1823 function IntlParseDate(formatter, value) {
1810 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter), 1824 return %InternalDateParse(%GetImplFromInitializedIntlObject(formatter),
1811 TO_STRING(value)); 1825 TO_STRING(value));
1812 } 1826 }
1813 1827
1814 1828
1815 // 0 because date is optional argument. 1829 // 0 because date is optional argument.
1816 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat'); 1830 AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0, 'dateformat');
1831 AddBoundMethod(Intl.DateTimeFormat, 'formatToParts', formatDateToParts, 0,
1832 'dateformat');
1817 1833
1818 1834
1819 /** 1835 /**
1820 * Returns canonical Area/Location(/Location) name, or throws an exception 1836 * Returns canonical Area/Location(/Location) name, or throws an exception
1821 * if the zone name is invalid IANA name. 1837 * if the zone name is invalid IANA name.
1822 */ 1838 */
1823 function canonicalizeTimeZoneID(tzID) { 1839 function canonicalizeTimeZoneID(tzID) {
1824 // Skip undefined zones. 1840 // Skip undefined zones.
1825 if (IS_UNDEFINED(tzID)) { 1841 if (IS_UNDEFINED(tzID)) {
1826 return tzID; 1842 return tzID;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 } 2309 }
2294 ); 2310 );
2295 2311
2296 utils.Export(function(to) { 2312 utils.Export(function(to) {
2297 to.AddBoundMethod = AddBoundMethod; 2313 to.AddBoundMethod = AddBoundMethod;
2298 to.IntlParseDate = IntlParseDate; 2314 to.IntlParseDate = IntlParseDate;
2299 to.IntlParseNumber = IntlParseNumber; 2315 to.IntlParseNumber = IntlParseNumber;
2300 }); 2316 });
2301 2317
2302 }) 2318 })
OLDNEW
« no previous file with comments | « no previous file | src/runtime/runtime.h » ('j') | src/runtime/runtime-i18n.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698