dolphindb 0.0.14 → 0.0.15

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
3
+ exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.ddb_sizes = exports.DdbType = exports.DdbForm = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const ws_1 = require("ws");
6
6
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
@@ -1095,34 +1095,79 @@ function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
1095
1095
  (0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
1096
1096
  }
1097
1097
  exports.datetime2str = datetime2str;
1098
- function timestamp2str(timestamp) {
1098
+ /** format timestamp (bigint) to string
1099
+ - timestamp: bigint value
1100
+ - format?:
1101
+ format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
1102
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1103
+ */
1104
+ function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1099
1105
  return timestamp === exports.nulls.int64 ?
1100
1106
  ''
1101
1107
  :
1102
- (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format('YYYY.MM.DD HH:mm:ss.SSS');
1108
+ (0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
1103
1109
  }
1104
1110
  exports.timestamp2str = timestamp2str;
1105
- function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss') {
1106
- return nanotimestamp === exports.nulls.int64 ?
1107
- ''
1108
- :
1109
- (0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format) + `.${nanotimestamp % 1000000000n}`;
1111
+ /** parse timestamp string to bigint value
1112
+ - str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1113
+ - format?:
1114
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
1115
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1116
+ */
1117
+ function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
1118
+ if (!str)
1119
+ return exports.nulls.int64;
1120
+ if (str.length !== format.length)
1121
+ throw new Error('The length of the timestamp string is not equal to the length of the format string');
1122
+ return BigInt(-exports.timezone_offset +
1123
+ (0, dayjs_1.default)(str, format).valueOf());
1124
+ }
1125
+ exports.str2timestamp = str2timestamp;
1126
+ /** format nanotimestamp value (bigint) to string
1127
+ - nanotimestamp: bigint value
1128
+ - format?:
1129
+ format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
1130
+ Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1131
+ https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1132
+ */
1133
+ function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1134
+ if (nanotimestamp === exports.nulls.int64)
1135
+ return '';
1136
+ const i_second_start = format.indexOf('ss');
1137
+ if (i_second_start === -1)
1138
+ throw new Error('The format string must contain the format for seconds (ss)');
1139
+ const i_second_end = i_second_start + 2;
1140
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1141
+ if (i_nanosecond_start === -1)
1142
+ throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
1143
+ return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
1144
+ format.slice(i_second_end, i_nanosecond_start) +
1145
+ String(nanotimestamp % 1000000000n));
1110
1146
  }
1111
1147
  exports.nanotimestamp2str = nanotimestamp2str;
1112
1148
  /** parse nano timestamp string to bigint value
1113
- - str: nano timestamp string, 如果为空字符串会返回对应的空值 (nulls.int64)
1114
- - format?: 对应传入字符串的到秒之前 (包括) 的格式串,默认是 `YYYY.MM.DD HH:mm:ss`
1149
+ - str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
1150
+ - format?:
1151
+ The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
1152
+ Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
1115
1153
  https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
1116
1154
  */
1117
- function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
1155
+ function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
1118
1156
  if (!str)
1119
1157
  return exports.nulls.int64;
1120
- if (str.length - format.length !== 9)
1121
- throw new Error('nanotimestamp 字符串长度减格式串长度应该等于 9');
1158
+ if (str.length !== format.length)
1159
+ throw new Error('nanotimestamp string length is not equal to format string length');
1160
+ const i_second_start = format.indexOf('ss');
1161
+ if (i_second_start === -1)
1162
+ throw new Error('The format string must contain the format for seconds (ss)');
1163
+ const i_second_end = i_second_start + 2;
1164
+ const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
1165
+ if (i_nanosecond_start === -1)
1166
+ throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
1122
1167
  return (BigInt(-exports.timezone_offset +
1123
- (0, dayjs_1.default)(str.slice(0, format.length), format).valueOf()) * 1000000n
1168
+ (0, dayjs_1.default)(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
1124
1169
  +
1125
- BigInt(str.slice(format.length)));
1170
+ BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
1126
1171
  }
1127
1172
  exports.str2nanotimestamp = str2nanotimestamp;
1128
1173
  class DDB {