konzen commented on code in PR #21739:
URL: https://github.com/apache/echarts/pull/21739#discussion_r3807433379
##########
src/util/time.ts:
##########
@@ -409,117 +480,545 @@ export function getUnitFromValue(
}
}
-// export function getUnitValue(
-// value: number | Date,
-// unit: TimeUnit,
-// isUTC: boolean
-// ) : number {
-// const date = zrUtil.isNumber(value)
-// ? numberUtil.parseDate(value)
-// : value;
-// unit = unit || getUnitFromValue(value, isUTC);
-
-// switch (unit) {
-// case 'year':
-// return date[fullYearGetterName(isUTC)]();
-// case 'half-year':
-// return date[monthGetterName(isUTC)]() >= 6 ? 1 : 0;
-// case 'quarter':
-// return Math.floor((date[monthGetterName(isUTC)]() + 1) / 4);
-// case 'month':
-// return date[monthGetterName(isUTC)]();
-// case 'day':
-// return date[dateGetterName(isUTC)]();
-// case 'half-day':
-// return date[hoursGetterName(isUTC)]() / 24;
-// case 'hour':
-// return date[hoursGetterName(isUTC)]();
-// case 'minute':
-// return date[minutesGetterName(isUTC)]();
-// case 'second':
-// return date[secondsGetterName(isUTC)]();
-// case 'millisecond':
-// return date[millisecondsGetterName(isUTC)]();
-// }
-// }
-
/**
* e.g.,
* If timeUnit is 'year', return the Jan 1st 00:00:00 000 of that year.
* If timeUnit is 'day', return the 00:00:00 000 of that day.
*
* @return The input date.
*/
-export function roundTime(date: Date, timeUnit: PrimaryTimeUnit, isUTC:
boolean): Date {
- switch (timeUnit) {
- case 'year':
- date[monthSetterName(isUTC)](0);
- case 'month':
- date[dateSetterName(isUTC)](1);
- case 'day':
- date[hoursSetterName(isUTC)](0);
- case 'hour':
- date[minutesSetterName(isUTC)](0);
- case 'minute':
- date[secondsSetterName(isUTC)](0);
- case 'second':
- date[millisecondsSetterName(isUTC)](0);
+export function roundTime(
+ date: Date,
+ timeUnit: PrimaryTimeUnit,
+ timeZone: string
+): Date;
+/**
+ * @deprecated Pass a time zone string instead of the legacy `isUTC` boolean.
+ */
+export function roundTime(
+ date: Date,
+ timeUnit: PrimaryTimeUnit,
+ isUTC: boolean
+): Date;
+export function roundTime(
+ date: Date,
+ timeUnit: PrimaryTimeUnit,
+ timeZoneOrUTC: string | boolean
+): Date {
+ if (__DEV__ && typeof timeZoneOrUTC === 'boolean') {
+ deprecateReplaceLog('isUTC boolean parameter', 'timeZone string
parameter', 'echarts.time.roundTime');
}
+ date.setTime(roundTimeInTimeZone(
+ date.getTime(), timeUnit, normalizeTimeZone(timeZoneOrUTC)
+ ));
return date;
}
+function normalizeTimeZone(timeZoneOrUTC: string | boolean): string {
+ return typeof timeZoneOrUTC === 'string'
+ ? timeZoneOrUTC
+ : timeZoneOrUTC ? 'UTC' : getSystemTimeZone();
Review Comment:
Fixed in 438a10760. Invalid time-zone errors are now normalized at the
shared formatter-creation boundary, so format, leveledFormat, getUnitFromValue,
and roundTime consistently throw Invalid time zone: .... Tests cover all four
public helpers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]