Debian Codegraph @

addons/point_of_sale/static/src/app/hooks/time_hook.js

raw
1 import { useState, useEffect } from "@odoo/owl";
2 import { localization } from "@web/core/l10n/localization";
3 const { DateTime } = luxon;
4
5 export function useTime() {
6 const state = useState({ hours: "", day: "", date: "" });
7 const timeFormat = localization.timeFormat;
8 const dateFormat = localization.dateFormat
9 .replace(/MM/g, "LLLL")
10 .replace(/\/yy$/, "/yyyy")
11 .replace(/[^a-zA-Z]+/g, ", ");
12 function setTime() {
13 const dateNow = DateTime.now();
14 state.hours = dateNow.toFormat(timeFormat);
15 state.day = dateNow.toFormat("cccc");
16 state.date = dateNow.toFormat(dateFormat);
17 }
18 useEffect(
19 () => {
20 const interval = setInterval(() => setTime(), 500);
21
22 return () => {
23 clearInterval(interval);
24 };
25 },
26 () => []
27 );
28 setTime();
29 return state;
30 }