summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/shared')
-rw-r--r--gui/src/shared/account-expiry.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/gui/src/shared/account-expiry.ts b/gui/src/shared/account-expiry.ts
new file mode 100644
index 0000000000..8e4c9b2ece
--- /dev/null
+++ b/gui/src/shared/account-expiry.ts
@@ -0,0 +1,39 @@
+import moment from 'moment';
+import { sprintf } from 'sprintf-js';
+import { messages } from './gettext';
+
+export default class AccountExpiry {
+ private expiry: moment.Moment;
+
+ constructor(isoString: string, locale: string) {
+ this.expiry = moment(isoString).locale(locale);
+ }
+
+ public hasExpired(): boolean {
+ return this.willHaveExpiredAt(new Date());
+ }
+
+ public willHaveExpiredAt(date: Date): boolean {
+ return this.expiry.isSameOrBefore(date);
+ }
+
+ public formattedDate(): string {
+ return this.expiry.format('L LTS');
+ }
+
+ public durationUntilExpiry(): string {
+ return this.expiry.fromNow(true);
+ }
+
+ public remainingTime(): string {
+ const duration = this.durationUntilExpiry();
+
+ return sprintf(
+ // TRANSLATORS: The remaining time left on the account displayed across the app.
+ // TRANSLATORS: Available placeholders:
+ // TRANSLATORS: %(duration)s - a localized remaining time (in minutes, hours, or days) until the account expiry
+ messages.pgettext('account-expiry', '%(duration)s left'),
+ { duration },
+ );
+ }
+}