@fileverse-dev/fortune-core 1.2.56 → 1.2.58-sm-fix-patch-1

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/es/modules/ssf.js CHANGED
@@ -967,7 +967,7 @@ var make_ssf = function make_ssf(SSF) {
967
967
  if (v < 0) return "";
968
968
  if (dt == null) {
969
969
  dt = parse_date_code(v, opts);
970
- if (dt == null) return "#####";
970
+ if (dt == null) return v;
971
971
  }
972
972
  o = c;
973
973
  while (++i < fmt.length && fmt.charAt(i).toLowerCase() === c) o += c;
@@ -1360,6 +1360,22 @@ var make_ssf = function make_ssf(SSF) {
1360
1360
  }
1361
1361
  return [l, ff];
1362
1362
  }
1363
+ function checkUnixTimestampAndUnit(n) {
1364
+ if (typeof n !== "number" || !Number.isFinite(n)) return null;
1365
+ if (!Number.isInteger(n)) return null;
1366
+ if (n < 0) return null;
1367
+ var minSec = 0; // 1970-01-01
1368
+ var maxSec = 4102444800; // ~2100-01-01
1369
+ var minMs = minSec * 1000;
1370
+ var maxMs = maxSec * 1000;
1371
+ if (n >= minSec && n <= maxSec) {
1372
+ return "seconds";
1373
+ }
1374
+ if (n >= minMs && n <= maxMs) {
1375
+ return "milliseconds";
1376
+ }
1377
+ return null;
1378
+ }
1363
1379
  function format(fmt, v, o) {
1364
1380
  if (o == null) o = {};
1365
1381
  var sfmt = "";
@@ -1374,6 +1390,16 @@ var make_ssf = function make_ssf(SSF) {
1374
1390
  break;
1375
1391
  }
1376
1392
 
1393
+ //unix timestamp detection
1394
+ if (typeof v === "number" && fmt_is_date && fmt_is_date(sfmt)) {
1395
+ var unit = checkUnixTimestampAndUnit(v);
1396
+ if (unit === "seconds") {
1397
+ v = new Date(v * 1000);
1398
+ } else if (unit === "milliseconds") {
1399
+ v = new Date(v);
1400
+ }
1401
+ }
1402
+
1377
1403
  //new runze 增加万 亿 格式
1378
1404
  //注:"w":2万2500 "w0":2万2500 "w0.0":2万2500.2 "w0.00":2万2500.23......自定义精确度
1379
1405
  var reg = /^(w|W)((0?)|(0\.0+))$/;
@@ -973,7 +973,7 @@ var make_ssf = function make_ssf(SSF) {
973
973
  if (v < 0) return "";
974
974
  if (dt == null) {
975
975
  dt = parse_date_code(v, opts);
976
- if (dt == null) return "#####";
976
+ if (dt == null) return v;
977
977
  }
978
978
  o = c;
979
979
  while (++i < fmt.length && fmt.charAt(i).toLowerCase() === c) o += c;
@@ -1366,6 +1366,22 @@ var make_ssf = function make_ssf(SSF) {
1366
1366
  }
1367
1367
  return [l, ff];
1368
1368
  }
1369
+ function checkUnixTimestampAndUnit(n) {
1370
+ if (typeof n !== "number" || !Number.isFinite(n)) return null;
1371
+ if (!Number.isInteger(n)) return null;
1372
+ if (n < 0) return null;
1373
+ var minSec = 0; // 1970-01-01
1374
+ var maxSec = 4102444800; // ~2100-01-01
1375
+ var minMs = minSec * 1000;
1376
+ var maxMs = maxSec * 1000;
1377
+ if (n >= minSec && n <= maxSec) {
1378
+ return "seconds";
1379
+ }
1380
+ if (n >= minMs && n <= maxMs) {
1381
+ return "milliseconds";
1382
+ }
1383
+ return null;
1384
+ }
1369
1385
  function format(fmt, v, o) {
1370
1386
  if (o == null) o = {};
1371
1387
  var sfmt = "";
@@ -1380,6 +1396,16 @@ var make_ssf = function make_ssf(SSF) {
1380
1396
  break;
1381
1397
  }
1382
1398
 
1399
+ //unix timestamp detection
1400
+ if (typeof v === "number" && fmt_is_date && fmt_is_date(sfmt)) {
1401
+ var unit = checkUnixTimestampAndUnit(v);
1402
+ if (unit === "seconds") {
1403
+ v = new Date(v * 1000);
1404
+ } else if (unit === "milliseconds") {
1405
+ v = new Date(v);
1406
+ }
1407
+ }
1408
+
1383
1409
  //new runze 增加万 亿 格式
1384
1410
  //注:"w":2万2500 "w0":2万2500 "w0.0":2万2500.2 "w0.00":2万2500.23......自定义精确度
1385
1411
  var reg = /^(w|W)((0?)|(0\.0+))$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.56",
3
+ "version": "1.2.58-sm-fix-patch-1",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",