fixing get time

This commit is contained in:
sanjayk03-dev
2024-08-28 13:31:32 +05:30
parent 71a1775221
commit ae23f756ea
2 changed files with 25 additions and 3 deletions

View File

@@ -39,7 +39,6 @@ module.exports = {
z_slider: false,
z_slider_variant: " ",
config: "",
current_date_time: `${new Date()}`.split(" ").slice(1, 5).join(" "),
selected_date: null,
selected_hours: `${new Date().getHours()}`,
selected_minutes: `${new Date().getMinutes()}`,
@@ -50,6 +49,22 @@ module.exports = {
this.autoCheckUpgrade = this.config.admin["auto-check-upgrade"];
},
computed: {
get_current_time: async function () {
try {
const response = await api.get("time");
if (response.timeinfo) {
const { timeinfo } = response;
return timeinfo.split(": ")[1].split(" U")[0];
} else {
return " ";
}
} catch (error) {
console.error(error);
}
},
},
methods: {
backup: function () {
document.getElementById("download-target").src =
@@ -153,6 +168,14 @@ module.exports = {
if (!this.selected_date || !this.selected_hours || !this.selected_minutes) {
return;
}
if (
this.selected_hours < 0 ||
this.selected_hours > 23 ||
this.selected_minutes < 0 ||
this.selected_minutes > 59
) {
return alert("Invalid Time");
}
try {
const datetime = `${this.selected_date} ${this.selected_hours
.toString()
@@ -161,7 +184,6 @@ module.exports = {
if (response == "ok") {
alert("Date/Time updated successfully.");
this.current_date_time = `${new Date()}`.split(" ").slice(1, 5).join(" ");
} else {
throw response;
}

View File

@@ -67,7 +67,7 @@ script#admin-general-view-template(type="text/x-template")
h2 Date/Time
p
strong Current Date/Time:
| {{current_date_time}}
| {{get_current_time}}
.pure-form
input(id="date" type="date" v-model="selected_date")
input(id="hours" type="number" v-model="selected_hours" placeholder="HH" maxlength="2" min="0" max="23" style="width:45px")