MCPcopy
hub / github.com/iamkun/dayjs / constructor

Method constructor

src/plugin/duration/index.js:61–102  ·  view source on GitHub ↗
(input, unit, locale)

Source from the content-addressed store, hash-verified

59
60class Duration {
61 constructor(input, unit, locale) {
62 this.$d = {}
63 this.$l = locale
64 if (input === undefined) {
65 this.$ms = 0
66 this.parseFromMilliseconds()
67 }
68 if (unit) {
69 return wrapper(input * unitToMS[prettyUnit(unit)], this)
70 }
71 if (typeof input === 'number') {
72 this.$ms = input
73 this.parseFromMilliseconds()
74 return this
75 }
76 if (typeof input === 'object') {
77 Object.keys(input).forEach((k) => {
78 this.$d[prettyUnit(k)] = input[k]
79 })
80 this.calMilliseconds()
81 return this
82 }
83 if (typeof input === 'string') {
84 const d = input.match(DURATION_REGEX_PARSE)
85 if (d) {
86 const properties = d.slice(2)
87 const numberD = properties.map(value => (value != null ? Number(value) : 0));
88 [
89 this.$d.years,
90 this.$d.months,
91 this.$d.weeks,
92 this.$d.days,
93 this.$d.hours,
94 this.$d.minutes,
95 this.$d.seconds
96 ] = numberD
97 this.calMilliseconds()
98 return this
99 }
100 }
101 return this
102 }
103
104 calMilliseconds() {
105 this.$ms = Object.keys(this.$d).reduce((total, unit) => (

Callers

nothing calls this directly

Calls 4

parseFromMillisecondsMethod · 0.95
calMillisecondsMethod · 0.95
wrapperFunction · 0.70
prettyUnitFunction · 0.70

Tested by

no test coverage detected