-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomation-GetTime_copy.yml
105 lines (101 loc) · 2.74 KB
/
automation-GetTime_copy.yml
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
commonfields:
id: 6d8e6151-5f3c-4e58-8379-5e987956c45f
version: 1
name: GetTime_copy
script: |-
var d = new Date();
if ((args.date) && (args.date.length > 0)){
d = new Date(args.date);
}
if (args.monthsAgo){
d.setMonth(d.getMonth() - args.monthsAgo);
}
if (args.minutesAgo){
d.setMinutes(d.getMinutes() - args.minutesAgo);
}
if (args.hoursAgo){
d.setHours(d.getHours() - args.hoursAgo);
}
prefix = '';
if (args.contextKey) {
prefix = args.contextKey;
}
var timeStr = String(d);
if ((args.dateFormat) && (args.dateFormat.length > 0)){
switch(args.dateFormat.toLowerCase()) {
case 'iso':
timeStr = d.toISOString();
break;
case 'gmt':
case 'utc':
timeStr = d.toUTCString();
break;
case 'locale':
timeStr = d.toLocaleString();
break;
case 'date':
timeStr = d.toDateString();
break;
case 'year':
timeStr = d.getFullYear();
break;
case 'month':
timeStr = d.getMonth();
break;
case 'day':
timeStr = d.getDate();
break;
case 'dayinweek':
timeStr = d.getDay();
break;
case 'hours':
timeStr = d.getHours();
break;
case 'utchours':
timeStr = d.getUTCHours();
break;
case 'minutes':
timeStr = d.getMinutes();
break;
default:
throw 'Unsupported date format: '+args.dateFormat
}
}
context = {};
context[prefix+'TimeNowUnix'] = d.getTime();
context[prefix+'TimeNow'] = timeStr;
return {
Type : entryTypes.note,
Contents : timeStr,
ContentsFormat : formats.json,
HumanReadable : timeStr,
EntryContext : context
};
type: javascript
tags:
- Utility
comment: |
Retrieves the current date and time.
enabled: true
args:
- name: date
default: true
description: The date to use in the object
- name: dateFormat
description: The date format for the result, can be ISO/GMT/UTC/Locale/Date/Year/Month/Day/DayInWeek/Hours
- name: contextKey
description: prefix the keys in the context for the results
- name: monthsAgo
description: Will subtract monthsAgo months from current time
- name: minutesAgo
description: Will subtract minutesAgo minutes from current time
- name: hoursAgo
description: Will subtract hoursAgo hours from current time
outputs:
- contextPath: TimeNowUnix
description: number of milliseconds since 1970/01/01
- contextPath: TimeNow
description: current time in ISO format
scripttarget: 0
runonce: false
runas: DBotWeakRole