changing time format
This commit is contained in:
@@ -39,7 +39,10 @@ module.exports = {
|
|||||||
z_slider: false,
|
z_slider: false,
|
||||||
z_slider_variant: " ",
|
z_slider_variant: " ",
|
||||||
config: "",
|
config: "",
|
||||||
current_time: "",
|
current_time: null,
|
||||||
|
current_timezone: "",
|
||||||
|
selected_timezone: "",
|
||||||
|
time_zones: [],
|
||||||
is_loading_time: false,
|
is_loading_time: false,
|
||||||
selected_date: null,
|
selected_date: null,
|
||||||
selected_hours: `${new Date().getHours()}`,
|
selected_hours: `${new Date().getHours()}`,
|
||||||
@@ -58,16 +61,27 @@ module.exports = {
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
get_current_time: function () {
|
get_current_time: function () {
|
||||||
if (this.config.admin.time_format == true) {
|
try {
|
||||||
return this.current_time;
|
if (this.current_time == null) {
|
||||||
} else if (this.current_time.length != 0) {
|
return "Loading...";
|
||||||
const date_time_array = this.current_time.split(" ");
|
}
|
||||||
const [hour, minutes, seconds] = date_time_array[2].split(":");
|
const options = {
|
||||||
const suffix = hour >= 12 ? "PM" : "AM";
|
year: "numeric",
|
||||||
const hour12 = (hour % 12 || 12).toString().padStart(2, "0");
|
month: "2-digit",
|
||||||
return `${date_time_array[0]} ${date_time_array[1]} ${hour12}:${minutes}:${seconds} ${suffix}`;
|
day: "2-digit",
|
||||||
} else {
|
hour: "2-digit",
|
||||||
return "";
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
hour12: this.config.admin.time_format === true,
|
||||||
|
};
|
||||||
|
if (this.current_timezone != "") {
|
||||||
|
options.timeZone = this.current_timezone;
|
||||||
|
}
|
||||||
|
const formatter = new Intl.DateTimeFormat("en-US", options);
|
||||||
|
return formatter.format(this.current_time);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return "Error loading time...";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -78,14 +92,24 @@ module.exports = {
|
|||||||
this.is_loading_time = true;
|
this.is_loading_time = true;
|
||||||
const response = await api.get("time");
|
const response = await api.get("time");
|
||||||
if (response.timeinfo) {
|
if (response.timeinfo) {
|
||||||
const { timeinfo } = response;
|
const { timeinfo, timezones } = response;
|
||||||
this.current_time = timeinfo.split(": ")[1].split(" U")[0];
|
|
||||||
} else {
|
this.time_zones = timezones.split("\n");
|
||||||
this.current_time = " ";
|
|
||||||
|
const universal_time = timeinfo.match(/Universal time:\s*(.*) UTC/);
|
||||||
|
const time_zone = timeinfo.match(/Time zone:\s*([^ ]*)/);
|
||||||
|
|
||||||
|
if (universal_time) {
|
||||||
|
this.current_time = newDate(universal_time[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_zone) {
|
||||||
|
this.current_timezone = time_zone[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching time:", error);
|
console.error("Error fetching time:", error);
|
||||||
this.current_time = "Error fetching time";
|
alert("Error fetching time");
|
||||||
} finally {
|
} finally {
|
||||||
this.is_loading_time = false;
|
this.is_loading_time = false;
|
||||||
}
|
}
|
||||||
@@ -236,7 +260,16 @@ module.exports = {
|
|||||||
throw response;
|
throw response;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert("Error updating time: ", error);
|
console.error(error);
|
||||||
|
alert("Error updating time");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
change_timezone: function () {
|
||||||
|
try {
|
||||||
|
console.log(this.selected_timezone);
|
||||||
|
} catch (error) {
|
||||||
|
alert("Error updating time zone");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user