@saihu/common 1.1.14 → 1.1.16

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.
@@ -1,3 +1,6 @@
1
1
  export declare function getCurrentDate(): string;
2
2
  export declare function getTomorrowDate(): string;
3
+ export declare function getCurrentChinaTime(): Date;
4
+ export declare function convertUtcToChinaTime(utcTimeString: string): string;
5
+ export declare function convertUtcToChinaTimeFormatted(utcTimeString: string, format?: string): string;
3
6
  //# sourceMappingURL=times.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"times.d.ts","sourceRoot":"","sources":["../../src/util/times.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,eAAe,WAE9B"}
1
+ {"version":3,"file":"times.d.ts","sourceRoot":"","sources":["../../src/util/times.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,WAE7B;AAED,wBAAgB,eAAe,WAE9B;AAED,wBAAgB,mBAAmB,SAElC;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,MAAM,EACrB,MAAM,GAAE,MAA8B,GACrC,MAAM,CAER"}
@@ -5,10 +5,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getCurrentDate = getCurrentDate;
7
7
  exports.getTomorrowDate = getTomorrowDate;
8
+ exports.getCurrentChinaTime = getCurrentChinaTime;
9
+ exports.convertUtcToChinaTime = convertUtcToChinaTime;
10
+ exports.convertUtcToChinaTimeFormatted = convertUtcToChinaTimeFormatted;
8
11
  const dayjs_1 = __importDefault(require("dayjs"));
12
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
13
+ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
14
+ // Enable timezone support
15
+ dayjs_1.default.extend(utc_1.default);
16
+ dayjs_1.default.extend(timezone_1.default);
9
17
  function getCurrentDate() {
10
18
  return (0, dayjs_1.default)().format('YYYY-MM-DD');
11
19
  }
12
20
  function getTomorrowDate() {
13
21
  return (0, dayjs_1.default)().add(1, 'day').format('YYYY-MM-DD');
14
22
  }
23
+ function getCurrentChinaTime() {
24
+ return (0, dayjs_1.default)().tz('Asia/Shanghai').toDate();
25
+ }
26
+ function convertUtcToChinaTime(utcTimeString) {
27
+ return dayjs_1.default.utc(utcTimeString).tz('Asia/Shanghai').format();
28
+ }
29
+ function convertUtcToChinaTimeFormatted(utcTimeString, format = 'YYYY-MM-DD HH:mm:ss') {
30
+ return dayjs_1.default.utc(utcTimeString).tz('Asia/Shanghai').format(format);
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",