dolphindb 2.0.1001 → 2.0.1003

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1217,10 +1217,12 @@ export class DdbObj {
1217
1217
  }
1218
1218
  }
1219
1219
  /** 整数一定用这个 number formatter, InspectOptions.decimals 不传也用这个 */
1220
- let default_formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1220
+ let default_formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1221
1221
  let _decimals = 20;
1222
1222
  /** 缓存,为了优化性能,通常 options.decimals 都是不变的 */
1223
- let _formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1223
+ let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
1224
+ /** 用来处理时差 To deal with jet lag */
1225
+ let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC' });
1224
1226
  /** 根据 DdbType 格式化单个元素 (value) 为字符串,空值返回 'null' 字符串 Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
1225
1227
  export function format(type, value, le, options = {}) {
1226
1228
  const { decimals } = options;
@@ -1229,7 +1231,7 @@ export function format(type, value, le, options = {}) {
1229
1231
  return default_formatter;
1230
1232
  if (decimals !== _decimals) {
1231
1233
  _decimals = decimals;
1232
- _formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: decimals, minimumFractionDigits: decimals });
1234
+ _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: decimals, minimumFractionDigits: decimals });
1233
1235
  }
1234
1236
  return _formatter;
1235
1237
  })();
@@ -1922,8 +1924,8 @@ export function second2str(second, format = 'HH:mm:ss') {
1922
1924
  export function datetime2ms(datetime) {
1923
1925
  if (datetime === null || datetime === nulls.int32)
1924
1926
  return null;
1925
- const ms = 1000 * datetime;
1926
- return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1927
+ const date = new Date(1000 * datetime);
1928
+ return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
1927
1929
  }
1928
1930
  export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1929
1931
  return (datetime === null || datetime === nulls.int32) ?
@@ -1934,8 +1936,8 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1934
1936
  export function timestamp2ms(timestamp) {
1935
1937
  if (timestamp === null || timestamp === nulls.int64)
1936
1938
  return null;
1937
- const ms = Number(timestamp);
1938
- return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1939
+ const date = new Date(Number(timestamp));
1940
+ return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
1939
1941
  }
1940
1942
  /** format timestamp (bigint) to string
1941
1943
  - timestamp: bigint value
@@ -1998,8 +2000,8 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1998
2000
  export function nanotimestamp2ns(nanotimestamp) {
1999
2001
  if (nanotimestamp === null || nanotimestamp === nulls.int64)
2000
2002
  return null;
2001
- const ms = Number(nanotimestamp / 1000000n);
2002
- return BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2003
+ const date = new Date(Number(nanotimestamp / 1000000n));
2004
+ return BigInt(dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
2003
2005
  }
2004
2006
  /** format nanotimestamp value (bigint) to string
2005
2007
  - nanotimestamp: bigint value
@@ -2025,9 +2027,7 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2025
2027
  const remainder = nanotimestamp % 1000000000n;
2026
2028
  const borrow = remainder < 0n;
2027
2029
  const ms = Number(nanotimestamp / 1000000n);
2028
- return (dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() +
2029
- // 去掉 9 位的纳秒部分,转化为毫秒
2030
- Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
2030
+ return (dayjs(_datetime_formatter.format(new Date(ms))).format(format.slice(0, i_second_end)) +
2031
2031
  format.slice(i_second_end, i_nanosecond_start) +
2032
2032
  String(borrow ?
2033
2033
  (remainder + 1000000000n) % 1000000000n