Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 89718dc

Browse files
committed
GITHUB - Updated code to manage dayjs
1 parent 82aa2fd commit 89718dc

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

__tests__/main.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import * as process from 'process'
22
import * as cp from 'child_process'
33
import * as path from 'path'
44
import {expect, test} from '@jest/globals'
5+
import {time} from '../src/action/time'
56

67
test('wait 500 ms', async () => {
7-
var delta = Math.abs(500 - 50)
8-
expect(delta).toBeGreaterThan(449)
8+
await time()
9+
console.log('demo')
910
})
1011

1112
// shows how the runner will run a javascript action with env / stdout protocol

dist/index.js

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/action/time.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3838
exports.time = void 0;
3939
const core = __importStar(require("@actions/core"));
4040
const dayjs_1 = __importDefault(require("dayjs"));
41+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
42+
dayjs_1.default.extend(utc_1.default);
4143
function time() {
4244
return __awaiter(this, void 0, void 0, function* () {
4345
const timezone = core.getInput('timeZone'); // default: 0
4446
const formatStr = core.getInput('format'); // default: ''
45-
const str = (0, dayjs_1.default)(new Date(), formatStr, timezone).utcOffset();
46-
/**
47-
* console.log('time zone: ', timezone)
48-
* console.log('time format: ', formatStr)
49-
* console.log('time formatStr: ', str)
50-
*/
47+
const str = (0, dayjs_1.default)().utcOffset(timezone).format(formatStr);
48+
console.log('time zone: ', timezone);
49+
console.log('time format: ', formatStr);
50+
console.log('time formatStr: ', str);
5151
core.setOutput('time', str);
5252
});
5353
}

src/action/time.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import * as core from '@actions/core'
22
import dayjs from 'dayjs'
33

4+
import dayjsPluginUTC from 'dayjs/plugin/utc'
5+
dayjs.extend(dayjsPluginUTC)
6+
47
export async function time(): Promise<void> {
58
const timezone = core.getInput('timeZone') // default: 0
69
const formatStr = core.getInput('format') // default: ''
7-
const str = dayjs(new Date(), formatStr, timezone).utcOffset()
8-
/**
9-
* console.log('time zone: ', timezone)
10-
* console.log('time format: ', formatStr)
11-
* console.log('time formatStr: ', str)
12-
*/
10+
const str = dayjs().utcOffset(timezone).format(formatStr)
11+
12+
console.log('time zone: ', timezone)
13+
console.log('time format: ', formatStr)
14+
console.log('time formatStr: ', str)
15+
1316
core.setOutput('time', str)
1417
}

0 commit comments

Comments
 (0)