nixos-configs/nixosModules/ags/config/ts/bar/items/clock.ts

24 lines
681 B
TypeScript
Raw Normal View History

const { Label } = Widget;
2024-01-22 10:23:32 -05:00
const { new_now_local } = imports.gi.GLib.DateTime;
2023-11-27 15:50:20 -05:00
export default () => Label({ class_name: 'clock' })
.poll(1000, (self) => {
2024-01-22 10:23:32 -05:00
const time = new_now_local();
2023-11-27 15:50:20 -05:00
2024-01-22 10:23:32 -05:00
const dayName = time.format('%a. ');
const dayNum = time.get_day_of_month();
2024-08-01 14:00:50 -04:00
const date = time.format(' %b. ');
const hour = (new Date().toLocaleString([], {
hour: 'numeric',
minute: 'numeric',
hour12: true,
}) ?? '')
.replace('a.m.', 'AM')
.replace('p.m.', 'PM');
2024-01-22 10:23:32 -05:00
if (dayNum && dayName && date) {
2024-08-01 14:00:50 -04:00
self.label = dayName + dayNum + date + hour;
2024-01-22 10:23:32 -05:00
}
});