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/README.md CHANGED
@@ -43,6 +43,7 @@ npm install dolphindb
43
43
 
44
44
  ## Usage
45
45
  ### 0. Initialize and connect to DolphinDB
46
+ #### NPM
46
47
  ```ts
47
48
  import { DDB } from 'dolphindb'
48
49
  // The import method for existing projects using CommonJS modules is const { DDB } = await import('dolphindb')
@@ -58,6 +59,19 @@ let ddb = new DDB('ws://127.0.0.1:8848')
58
59
  await ddb.connect()
59
60
  ```
60
61
 
62
+ #### CDN
63
+ ```html
64
+ <script src="https://cdn.dolphindb.cn/assets/api.umd.js"></script>
65
+ <script>
66
+ let ddb = new dolphindb.DDB('ws://127.0.0.1:8848')
67
+ console.log(ddb)
68
+ </script>
69
+ ```
70
+
71
+ Code completion, function prompt data:
72
+ https://cdn.dolphindb.cn/assets/docs.zh.json
73
+ https://cdn.dolphindb.cn/assets/docs.en.json
74
+
61
75
  #### DDB options
62
76
  ```ts
63
77
  let ddb = new DDB('ws://127.0.0.1:8848')
package/README.zh.md CHANGED
@@ -43,6 +43,7 @@ npm install dolphindb
43
43
 
44
44
  ## 用法
45
45
  ### 0. 初始化并连接到 DolphinDB
46
+ #### NPM
46
47
  ```ts
47
48
  import { DDB } from 'dolphindb'
48
49
  // 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = await import('dolphindb')
@@ -58,6 +59,20 @@ let ddb = new DDB('ws://127.0.0.1:8848')
58
59
  await ddb.connect()
59
60
  ```
60
61
 
62
+ #### CDN
63
+ ```html
64
+ <script src="https://cdn.dolphindb.cn/assets/api.umd.js"></script>
65
+ <script>
66
+ let ddb = new dolphindb.DDB('ws://127.0.0.1:8848')
67
+ console.log(ddb)
68
+ </script>
69
+ ```
70
+
71
+ 代码补全、函数提示数据:
72
+ https://cdn.dolphindb.cn/assets/docs.zh.json
73
+ https://cdn.dolphindb.cn/assets/docs.en.json
74
+
75
+
61
76
  #### DDB 选项
62
77
  ```ts
63
78
  let ddb = new DDB('ws://127.0.0.1:8848', {
package/browser.js CHANGED
@@ -1217,10 +1217,12 @@ export class DdbObj {
1217
1217
  }
1218
1218
  }
1219
1219
  /** 整数一定用这个 number formatter, InspectOptions.decimals 不传也用这个 Integer must use this number formatter, InspectOptions.decimals also use this if not passed */
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 都是不变的 Cache, in order to optimize performance, usually options.decimals are unchanged */
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) 为字符串 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, nullstr = false, colors = false, quote = false } = 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
  })();
@@ -1927,8 +1929,8 @@ export function second2str(second, format = 'HH:mm:ss') {
1927
1929
  export function datetime2ms(datetime) {
1928
1930
  if (datetime === null || datetime === nulls.int32)
1929
1931
  return null;
1930
- const ms = 1000 * datetime;
1931
- return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1932
+ const date = new Date(1000 * datetime);
1933
+ return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
1932
1934
  }
1933
1935
  export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1934
1936
  return (datetime === null || datetime === nulls.int32) ?
@@ -1939,8 +1941,8 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1939
1941
  export function timestamp2ms(timestamp) {
1940
1942
  if (timestamp === null || timestamp === nulls.int64)
1941
1943
  return null;
1942
- const ms = Number(timestamp);
1943
- return 1000 * 60 * new Date(ms).getTimezoneOffset() + ms;
1944
+ const date = new Date(Number(timestamp));
1945
+ return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
1944
1946
  }
1945
1947
  /** format timestamp (bigint) to string
1946
1948
  - timestamp: bigint value
@@ -2003,8 +2005,8 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
2003
2005
  export function nanotimestamp2ns(nanotimestamp) {
2004
2006
  if (nanotimestamp === null || nanotimestamp === nulls.int64)
2005
2007
  return null;
2006
- const ms = Number(nanotimestamp / 1000000n);
2007
- return BigInt(1000 * 60 * new Date(ms).getTimezoneOffset()) * 1000000n + nanotimestamp;
2008
+ const date = new Date(Number(nanotimestamp / 1000000n));
2009
+ return BigInt(dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
2008
2010
  }
2009
2011
  /** format nanotimestamp value (bigint) to string
2010
2012
  - nanotimestamp: bigint value
@@ -2030,9 +2032,7 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
2030
2032
  const remainder = nanotimestamp % 1000000000n;
2031
2033
  const borrow = remainder < 0n;
2032
2034
  const ms = Number(nanotimestamp / 1000000n);
2033
- return (dayjs(1000 * 60 * new Date(ms).getTimezoneOffset() +
2034
- // 去掉 9 位的纳秒部分,转化为毫秒
2035
- Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
2035
+ return (dayjs(_datetime_formatter.format(new Date(ms))).format(format.slice(0, i_second_end)) +
2036
2036
  format.slice(i_second_end, i_nanosecond_start) +
2037
2037
  String(borrow ?
2038
2038
  (remainder + 1000000000n) % 1000000000n