change created_at to epoch created_time

This commit is contained in:
Muhammad Izza Alfiansyah 2024-05-03 13:16:50 +07:00
parent 9b99cf74cc
commit e0d43f62b6
6 changed files with 24 additions and 24 deletions

View File

@ -32,9 +32,7 @@ export default function () {
headers={["Tanggal", "Lama Fermentasi", "Rentang Suhu", "Status"]} headers={["Tanggal", "Lama Fermentasi", "Rentang Suhu", "Status"]}
items={items().map((item) => [ items={items().map((item) => [
getDates(item.created_at), getDates(item.created_at),
Math.round( Math.round((item.waktu_akhir - item.waktu_awal) / 3600) + " Jam",
getTimeDiff(item.waktu_awal, item.waktu_akhir) / (1000 * 60 * 60)
) + " Jam",
item.rentang_suhu + " C", item.rentang_suhu + " C",
<span <span
class={ class={

View File

@ -17,7 +17,7 @@ export default function () {
const { data } = await supabase const { data } = await supabase
.from("kondisi_tapai") .from("kondisi_tapai")
.select("*") .select("*")
.order("created_at", { ascending: false }) .order("created_time", { ascending: false })
.limit(10); .limit(10);
if (data != null && data.length > 0) { if (data != null && data.length > 0) {
@ -30,12 +30,12 @@ export default function () {
data.forEach((item) => { data.forEach((item) => {
setKadarGas((val) => { setKadarGas((val) => {
val.push(item.kadar_gas); val.push(item.kadar_gas.toString().slice(0, 4));
return val; return val;
}); });
setTimeStamps((val) => { setTimeStamps((val) => {
val.push(getTimes(item.created_at)); val.push(getTimes(item.created_time));
return val; return val;
}); });
}); });
@ -88,7 +88,7 @@ export default function () {
text: "Nilai", text: "Nilai",
}, },
min: 0, min: 0,
max: 50, max: 10,
}, },
}, },
}, },
@ -135,11 +135,15 @@ export default function () {
<div class="grid grid-cols-2 grow gap-5 "> <div class="grid grid-cols-2 grow gap-5 ">
<div class="bg-white rounded shadow min-h-24 flex flex-col items-center justify-center py-8"> <div class="bg-white rounded shadow min-h-24 flex flex-col items-center justify-center py-8">
<EyeDropperIcon class="w-12 h-12 inline-block" /> <EyeDropperIcon class="w-12 h-12 inline-block" />
<div class="text-3xl mt-5">{suhu()} °C</div> <div class="text-3xl mt-5">
{suhu().toString().slice(0, 4)} °C
</div>
</div> </div>
<div class="bg-white rounded shadow min-h-24 flex flex-col items-center justify-center py-8"> <div class="bg-white rounded shadow min-h-24 flex flex-col items-center justify-center py-8">
<BeakerIcon class="w-12 h-12 inline-block" /> <BeakerIcon class="w-12 h-12 inline-block" />
<div class="text-3xl mt-5">{kelembaban()} %</div> <div class="text-3xl mt-5">
{kelembaban().toString().slice(0, 4)} %
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -12,11 +12,9 @@ export default function () {
.from("kondisi_tapai") .from("kondisi_tapai")
.select("*") .select("*")
.eq("pengujian", true) .eq("pengujian", true)
.order("created_at", { ascending: false }); .order("created_time", { ascending: false });
setItems(data as KondisiTapai[]); setItems(data as KondisiTapai[]);
console.log(items());
}; };
onMount(async () => { onMount(async () => {
@ -40,11 +38,11 @@ export default function () {
class="my-5" class="my-5"
headers={["Tanggal", "Jam", "Kadar Gas", "Suhu", "Kelembaban"]} headers={["Tanggal", "Jam", "Kadar Gas", "Suhu", "Kelembaban"]}
items={items().map((item) => [ items={items().map((item) => [
getDates(item.created_at), getDates(item.created_time),
getTimes(item.created_at).slice(0, 5), getTimes(item.created_time).slice(0, 5),
item.kadar_gas + "%", item.kadar_gas.toString().slice(0, 4) + " %",
item.suhu + " C", item.suhu.toString().slice(0, 4) + " C",
item.kelembaban + "%", item.kelembaban.toString().slice(0, 4) + " %",
])} ])}
></Table> ></Table>
</div> </div>

View File

@ -1,7 +1,7 @@
export interface Histori { export interface Histori {
id: number; id: number;
waktu_awal: string; waktu_awal: number;
waktu_akhir: string; waktu_akhir: number;
rentang_suhu: string; rentang_suhu: string;
berhasil: boolean; berhasil: boolean;
created_at: string; created_at: string;

View File

@ -3,5 +3,5 @@ export interface KondisiTapai {
suhu: number; suhu: number;
kelembaban: number; kelembaban: number;
kadar_gas: number; kadar_gas: number;
created_at: string; created_time: number;
} }

View File

@ -1,5 +1,5 @@
export function getTimes(date: any = null) { export function getTimes(epochtime: any = null) {
const dates = !!date ? new Date(date) : new Date(); const dates = !!epochtime ? new Date(epochtime * 1000 - 7000 * 3600) : new Date();
const hour = dates.getHours() < 10 ? '0' + dates.getHours() : dates.getHours(); const hour = dates.getHours() < 10 ? '0' + dates.getHours() : dates.getHours();
const minute = dates.getMinutes() < 10 ? '0' + dates.getMinutes() : dates.getMinutes(); const minute = dates.getMinutes() < 10 ? '0' + dates.getMinutes() : dates.getMinutes();
@ -10,8 +10,8 @@ export function getTimes(date: any = null) {
return his; return his;
} }
export function getDates(date: any = null) { export function getDates(epochtime: any = null) {
const dates = !!date ? new Date(date) : new Date(); const dates = !!epochtime ? new Date((typeof epochtime == 'number') ? epochtime * 1000 - 7000 * 3600 : epochtime) : new Date();
const bulan = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember']; const bulan = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];