summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-02-10 16:37:45 +0100
committerOskar Nyberg <oskar@mullvad.net>2020-02-11 09:00:53 +0100
commit83a1b073c6616330fa48468deaa13ade13ed711c (patch)
tree2bf5396b4cd93baa1b551e74b60d8f9a4a5ce493 /gui/src/shared
parentc9b3e7f007b0dd340ea810bca05abef36a325b7f (diff)
downloadmullvadvpn-83a1b073c6616330fa48468deaa13ade13ed711c.tar.xz
mullvadvpn-83a1b073c6616330fa48468deaa13ade13ed711c.zip
Add account expiry warning notification
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 },
+ );
+ }
+}