~ehamberg/paw-unix-time

78aec6d3eb85bd6c4914bd1fbef17891310125cd — Erlend Hamberg 5 years ago 5c37bf3 master
Pick a better default value
1 files changed, 10 insertions(+), 2 deletions(-)

M UnixTime.js
M UnixTime.js => UnixTime.js +10 -2
@@ 4,15 4,23 @@ const ISODateString = d =>
    d.getUTCFullYear()+'-' + pad(d.getUTCMonth()+1)+'-' + pad(d.getUTCDate())+'T00:00Z';

class UnixTime {
    constructor() {
        this.today = ISODateString(new Date());
    }

    evaluate() {
        const ms = Date.parse(this.value);
        const ms = Date.parse(this.value || this.today);

        if (isNaN(ms)) return "invalid";

        return ms/1000|0;
    }

    text() { return isNaN(Date.parse(this.value)) ? "invalid date/time" : this.value; }
    text() {
        if (isNaN(Date.parse(this.value || this.today))) return "invalid date/time";

        return this.value || this.today;
    }
}

UnixTime.inputs = [