-
Notifications
You must be signed in to change notification settings - Fork 888
Expand file tree
/
Copy pathdatetime.js
More file actions
39 lines (35 loc) · 1.18 KB
/
datetime.js
File metadata and controls
39 lines (35 loc) · 1.18 KB
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
export default function(cell, formatterParams, onRendered){
var DT = this.table.dependencyRegistry.lookup(["luxon", "DateTime"], "DateTime");
var inputFormat = formatterParams.inputFormat || "yyyy-MM-dd HH:mm:ss";
var outputFormat = formatterParams.outputFormat || "dd/MM/yyyy HH:mm:ss";
var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
var value = cell.getValue();
if(typeof DT != "undefined"){
var newDatetime;
if(DT.isDateTime(value)){
newDatetime = value;
}else if(inputFormat === "x"){
newDatetime = DT.fromMillis(value);
}else if(inputFormat === "iso"){
newDatetime = DT.fromISO(String(value));
}else{
newDatetime = DT.fromFormat(String(value), inputFormat);
}
if(newDatetime.isValid){
if(formatterParams.timezone){
newDatetime = newDatetime.setZone(formatterParams.timezone);
}
return newDatetime.toFormat(outputFormat);
}else{
if(invalid === true || !value){
return value;
}else if(typeof invalid === "function"){
return invalid(value);
}else{
return invalid;
}
}
}else{
console.error("Format Error - 'datetime' formatter is dependant on luxon.js");
}
}