diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-02-10 16:37:45 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-02-11 09:00:53 +0100 |
| commit | 83a1b073c6616330fa48468deaa13ade13ed711c (patch) | |
| tree | 2bf5396b4cd93baa1b551e74b60d8f9a4a5ce493 /gui/src/shared | |
| parent | c9b3e7f007b0dd340ea810bca05abef36a325b7f (diff) | |
| download | mullvadvpn-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.ts | 39 |
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 }, + ); + } +} |
