summaryrefslogtreecommitdiffstats
path: root/webapp/utils/license_utils.jsx
blob: 0ee8b75de30e50d1c0ade4eff1e19474a9365a7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import Constants from 'utils/constants.jsx';

import React from 'react';
import {FormattedDate} from 'react-intl';

export function isLicenseExpiring() {
    if (window.mm_license.IsLicensed !== 'true') {
        return false;
    }

    const timeDiff = parseInt(global.window.mm_license.ExpiresAt, 10) - Date.now();
    return timeDiff <= Constants.LICENSE_EXPIRY_NOTIFICATION;
}

export function isLicenseExpired() {
    if (window.mm_license.IsLicensed !== 'true') {
        return false;
    }

    const timeDiff = parseInt(global.window.mm_license.ExpiresAt, 10) - Date.now();
    return timeDiff < 0;
}

export function isLicensePastGracePeriod() {
    if (window.mm_license.IsLicensed !== 'true') {
        return false;
    }

    const timeDiff = Date.now() - parseInt(global.window.mm_license.ExpiresAt, 10);
    return timeDiff > Constants.LICENSE_GRACE_PERIOD;
}

export function displayExpiryDate() {
    return (
        <FormattedDate
            value={new Date(parseInt(global.window.mm_license.ExpiresAt, 10))}
            day='2-digit'
            month='long'
            year='numeric'
        />
    );
}