dolphindb 2.0.514 → 2.0.515

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/browser.d.ts CHANGED
@@ -265,7 +265,7 @@ export declare function datetime2str(datetime: number, format?: string): string;
265
265
  export declare function timestamp2str(timestamp: bigint, format?: string): string;
266
266
  export declare function datehour2str(datehour: number, format?: string): string;
267
267
  /** parse timestamp string to bigint value
268
- - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
268
+ - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
269
269
  - format?:
270
270
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
271
271
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
@@ -281,7 +281,7 @@ export declare function nanotime2str(nanotime: bigint, format?: string): string;
281
281
  */
282
282
  export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
283
283
  /** parse nano timestamp string to bigint value
284
- - str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
284
+ - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
285
285
  - format?:
286
286
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
287
287
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
package/browser.js CHANGED
@@ -1180,7 +1180,6 @@ function format(type, value, le) {
1180
1180
  return int1282str(value, le);
1181
1181
  case DdbType.blob:
1182
1182
  return DdbObj.dec.decode(value.subarray(0, 1000)).quote('single');
1183
- case DdbType.complex:
1184
1183
  case DdbType.point: {
1185
1184
  let [x, y] = value;
1186
1185
  if (x === exports.nulls.double)
@@ -1189,6 +1188,14 @@ function format(type, value, le) {
1189
1188
  y = null;
1190
1189
  return `(${String(x)}, ${String(y)})`;
1191
1190
  }
1191
+ case DdbType.complex: {
1192
+ let [x, y] = value;
1193
+ if (x === exports.nulls.double)
1194
+ x = null;
1195
+ if (y === exports.nulls.double)
1196
+ y = null;
1197
+ return `${String(x)}+${String(y)}i`;
1198
+ }
1192
1199
  case DdbType.duration: {
1193
1200
  const { data, unit } = value;
1194
1201
  return `${data}${DdbDurationUnit[unit]}`;
@@ -1509,24 +1516,24 @@ class DdbTable extends DdbObj {
1509
1516
  exports.DdbTable = DdbTable;
1510
1517
  function date2str(date, format = 'YYYY.MM.DD') {
1511
1518
  return (date === null || date === exports.nulls.int32) ?
1512
- ''
1519
+ 'null'
1513
1520
  :
1514
1521
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * 24 * date).format(format);
1515
1522
  }
1516
1523
  exports.date2str = date2str;
1517
1524
  function month2str(month) {
1518
1525
  if (month === null || month === exports.nulls.int32)
1519
- return '';
1526
+ return 'null';
1520
1527
  if (month < 0)
1521
1528
  return String(month);
1522
- let _month = month % 12;
1523
- let year = Math.floor(month / 12);
1524
- return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}`;
1529
+ const _month = month % 12;
1530
+ const year = Math.trunc(month / 12);
1531
+ return `${String(year).padStart(4, '0')}.${String(_month + 1).padStart(2, '0')}M`;
1525
1532
  }
1526
1533
  exports.month2str = month2str;
1527
1534
  function time2str(time, format = 'HH:mm:ss.SSS') {
1528
1535
  return (time === null || time === exports.nulls.int32) ?
1529
- ''
1536
+ 'null'
1530
1537
  :
1531
1538
  (0, dayjs_1.default)(exports.timezone_offset + time)
1532
1539
  .format(format);
@@ -1534,7 +1541,7 @@ function time2str(time, format = 'HH:mm:ss.SSS') {
1534
1541
  exports.time2str = time2str;
1535
1542
  function minute2str(minute, format = 'HH:mm') {
1536
1543
  return (minute === null || minute === exports.nulls.int32) ?
1537
- ''
1544
+ 'null'
1538
1545
  :
1539
1546
  (0, dayjs_1.default)(exports.timezone_offset + 60 * 1000 * minute)
1540
1547
  .format(format);
@@ -1542,7 +1549,7 @@ function minute2str(minute, format = 'HH:mm') {
1542
1549
  exports.minute2str = minute2str;
1543
1550
  function second2str(second, format = 'HH:mm:ss') {
1544
1551
  return (second === null || second === exports.nulls.int32) ?
1545
- ''
1552
+ 'null'
1546
1553
  :
1547
1554
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * second)
1548
1555
  .format(format);
@@ -1550,7 +1557,7 @@ function second2str(second, format = 'HH:mm:ss') {
1550
1557
  exports.second2str = second2str;
1551
1558
  function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1552
1559
  return (datetime === null || datetime === exports.nulls.int32) ?
1553
- ''
1560
+ 'null'
1554
1561
  :
1555
1562
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1556
1563
  }
@@ -1563,26 +1570,26 @@ exports.datetime2str = datetime2str;
1563
1570
  */
1564
1571
  function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1565
1572
  return (timestamp === null || timestamp === exports.nulls.int64) ?
1566
- ''
1573
+ 'null'
1567
1574
  :
1568
1575
  (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1569
1576
  }
1570
1577
  exports.timestamp2str = timestamp2str;
1571
- function datehour2str(datehour, format = 'YYYY.MM.DD.HH') {
1578
+ function datehour2str(datehour, format = 'YYYY.MM.DDTHH') {
1572
1579
  return (datehour === null || datehour === exports.nulls.int32) ?
1573
- ''
1580
+ 'null'
1574
1581
  :
1575
1582
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * 3600 * datehour).format(format);
1576
1583
  }
1577
1584
  exports.datehour2str = datehour2str;
1578
1585
  /** parse timestamp string to bigint value
1579
- - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1586
+ - str: timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1580
1587
  - format?:
1581
1588
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1582
1589
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1583
1590
  */
1584
1591
  function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1585
- if (!str)
1592
+ if (!str || str === 'null')
1586
1593
  return exports.nulls.int64;
1587
1594
  if (str.length !== format.length)
1588
1595
  throw new Error('The length of the timestamp string is not equal to the length of the format string');
@@ -1591,6 +1598,10 @@ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1591
1598
  }
1592
1599
  exports.str2timestamp = str2timestamp;
1593
1600
  function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
1601
+ if (nanotime === null || nanotime === exports.nulls.int64)
1602
+ return 'null';
1603
+ if (nanotime < 0n)
1604
+ return String(nanotime);
1594
1605
  const i_second_start = format.indexOf('ss');
1595
1606
  if (i_second_start === -1)
1596
1607
  throw new Error('格式串必须包含秒的格式 (ss)');
@@ -1611,8 +1622,14 @@ exports.nanotime2str = nanotime2str;
1611
1622
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1612
1623
  */
1613
1624
  function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1625
+ // tests:
1626
+ // nanotimestamp2str(0n)
1627
+ // nanotimestamp2str(-1n)
1628
+ // nanotimestamp2str(-9_9999_9999n)
1629
+ // nanotimestamp2str(-10_0000_0000n)
1630
+ // nanotimestamp2str(-10_0000_0001n)
1614
1631
  if (nanotimestamp === null || nanotimestamp === exports.nulls.int64)
1615
- return '';
1632
+ return 'null';
1616
1633
  const i_second_start = format.indexOf('ss');
1617
1634
  if (i_second_start === -1)
1618
1635
  throw new Error('The format string must contain the format for seconds (ss)');
@@ -1620,20 +1637,27 @@ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSS
1620
1637
  const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1621
1638
  if (i_nanosecond_start === -1)
1622
1639
  throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1623
- return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1640
+ const remainder = nanotimestamp % 1000000000n;
1641
+ const borrow = remainder < 0n;
1642
+ return ((0, dayjs_1.default)(exports.timezone_offset +
1643
+ // 去掉 9 位的纳秒部分,转化为毫秒
1644
+ Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
1624
1645
  format.slice(i_second_end, i_nanosecond_start) +
1625
- String(nanotimestamp % 1000000000n).padStart(9, '0'));
1646
+ String(borrow ?
1647
+ (remainder + 1000000000n) % 1000000000n
1648
+ :
1649
+ remainder).padStart(9, '0'));
1626
1650
  }
1627
1651
  exports.nanotimestamp2str = nanotimestamp2str;
1628
1652
  /** parse nano timestamp string to bigint value
1629
- - str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1653
+ - str: nano timestamp string, If it is an empty string or 'null', it will return the corresponding empty value (nulls.int64)
1630
1654
  - format?:
1631
1655
  The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
1632
1656
  Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1633
1657
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1634
1658
  */
1635
1659
  function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1636
- if (!str)
1660
+ if (!str || str === 'null')
1637
1661
  return exports.nulls.int64;
1638
1662
  if (str.length !== format.length)
1639
1663
  throw new Error('nanotimestamp string length is not equal to format string length');