diff options
author | Determinant <ted.sybil@gmail.com> | 2019-02-10 01:39:31 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2019-02-10 01:39:31 -0500 |
commit | e5729baa785c3a85d02d8315817e3a57f7c5fcb9 (patch) | |
tree | 632f9a2210d7e3dae4790b1f0c50744536a809fb /src/duration.js | |
parent | 735d8e5aa8b590b37a16c0e1b52a688c43dd5c10 (diff) |
popup works
Diffstat (limited to 'src/duration.js')
-rw-r--r-- | src/duration.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/duration.js b/src/duration.js new file mode 100644 index 0000000..53de0ad --- /dev/null +++ b/src/duration.js @@ -0,0 +1,21 @@ +import moment from 'moment'; + +export class Duration { + constructor(value, unit) { + this.value = value + this.unit = unit + } + + toMoment() { + let m = moment.duration(this.value, this.unit); + if (m.isValid()) return m; + return null; + } + + static days(n) { return new Duration(n, 'days'); } + static weeks(n) { return new Duration(n, 'weeks'); } + static months(n) { return new Duration(n, 'months'); } + + deflate() { return { value: this.value, unit: this.unit }; } + static inflate = obj => new Duration(obj.value, obj.unit); +} |