kawkab-frontend
Version:
Kawkab frontend is a frontend library for the Kawkab framework
29 lines (28 loc) • 706 B
JavaScript
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/ar';
dayjs.extend(relativeTime);
export class Time {
date;
constructor(dateInput) {
this.date = dayjs(dateInput);
}
static now() {
return new Time();
}
format(formatStr = 'YYYY-MM-DD HH:mm:ss') {
return this.date.format(formatStr);
}
fromNow(locale = 'en') {
return this.date.locale(locale).fromNow();
}
add(value, unit) {
return new Time(this.date.add(value, unit));
}
subtract(value, unit) {
return new Time(this.date.subtract(value, unit));
}
toDate() {
return this.date.toDate();
}
}