nixos-configs/nixosModules/ags/v2/widgets/bar/items/clock.tsx

32 lines
827 B
TypeScript
Raw Normal View History

2024-09-27 16:52:33 -04:00
import { bind, Variable } from 'astal';
import GLib from 'gi://GLib?version=2.0';
export default () => {
const timeVar = Variable<string>('').poll(1000, (prev) => {
const time = GLib.DateTime.new_now_local();
const dayName = time.format('%a. ');
const dayNum = time.get_day_of_month();
const date = time.format(' %b. ');
const hour = (new Date().toLocaleString([], {
hour: 'numeric',
minute: 'numeric',
hour12: true,
}) ?? '')
.replace('a.m.', 'AM')
.replace('p.m.', 'PM');
return (dayNum && dayName && date) ?
(dayName + dayNum + date + hour) :
prev;
});
return (
<box className="bar-item">
<label label={bind(timeVar)} />
</box>
);
};