forked from josStorer/get-current-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
45 lines (39 loc) · 1.72 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const core = require("@actions/core");
var moment = require('moment');
function action () {
try {
const utcOffset = core.getInput('utcOffset', { required: false });
const format = core.getInput('format', { required: false });
const interval = core.getInput('interval', { required: false });
const intervalType = core.getInput('intervalType', { required: false });
let method = core.getInput('method', { required: false });
let time = moment().utcOffset(utcOffset);
if (interval && intervalType && +interval > 0) {
if (!method){
method = 'ceil';
}
const momentDuration = moment.duration(parseInt(interval), intervalType);
time = moment(Math[method]((+time) / (+momentDuration)) * (+momentDuration));
}
core.setOutput("utcOffset", utcOffset);
core.setOutput("format", format);
core.setOutput("method", method);
core.setOutput("time", time.toISOString());
core.setOutput("ISOTime", time.toISOString());
core.setOutput("readableTime", time.toString());
core.setOutput("formattedTime", time.format(format));
core.setOutput("fancyTime", time.format('MMM Do YYYY'));
let [year, month, day, hour, minute, second, millisecond] = time.toArray();
month = String(Number(month) + 1);
core.setOutput("year", year)
core.setOutput("month", month)
core.setOutput("day", day)
core.setOutput("hour", hour)
core.setOutput("minute", minute)
core.setOutput("second", second)
core.setOutput("millisecond", millisecond)
} catch (error) {
core.setFailed(error.message);
}
}
module.exports = action;