Commit e64fa14f authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Fix the format of date range older than Oct 15 1582

Bug: v8:9912
Change-Id: Ib9deba176f7aaa2ffca2db811c5273af673028ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1884955Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64621}
parent f3cbcdb2
......@@ -1874,7 +1874,6 @@ MaybeHandle<T> FormatRangeCommon(
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidTimeValue),
T);
}
icu::DateInterval interval(x, y);
icu::DateIntervalFormat* format =
LazyCreateDateIntervalFormat(isolate, date_time_format);
......@@ -1883,8 +1882,19 @@ MaybeHandle<T> FormatRangeCommon(
}
UErrorCode status = U_ZERO_ERROR;
icu::SimpleDateFormat* date_format =
date_time_format->icu_simple_date_format().raw();
const icu::Calendar* calendar = date_format->getCalendar();
std::unique_ptr<icu::Calendar> c1(calendar->clone());
std::unique_ptr<icu::Calendar> c2(calendar->clone());
c1->setTime(x, status);
c2->setTime(y, status);
// We need to format by Calendar because we need the Gregorian change
// adjustment already in the SimpleDateFormat to set the correct value of date
// older than Oct 15, 1582.
icu::FormattedDateInterval formatted =
format->formatToValue(interval, status);
format->formatToValue(*c1, *c2, status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIcuError), T);
}
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let df = new Intl.DateTimeFormat("en");
// A modern date
let d1 = new Date(2019, 3, 4);
let d2 = new Date(2019, 4, 5);
assertEquals(df.format(d1), df.formatRange(d1, d1));
assertEquals(df.format(d2), df.formatRange(d2, d2));
assertEquals("4/4/2019 – 5/5/2019", df.formatRange(d1, d2));
// An old date just before the Julian / Gregorian switch
let d3 = new Date(1582, 8, 13);
let d4 = new Date(1582, 9, 14);
assertEquals(df.format(d3), df.formatRange(d3, d3));
assertEquals(df.format(d4), df.formatRange(d4, d4));
assertEquals("9/13/1582 – 10/14/1582", df.formatRange(d3, d4));
// An older date
let d5 = new Date(1000, 0, 1);
let d6 = new Date(1001, 1, 2);
assertEquals(df.format(d5), df.formatRange(d5, d5));
assertEquals(df.format(d6), df.formatRange(d6, d6));
assertEquals("1/1/1000 – 2/2/1001", df.formatRange(d5, d6));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment