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

Function parseFormattedInput

src/plugin/customParseFormat/index.js:181–214  ·  view source on GitHub ↗
(input, format, utc, dayjs)

Source from the content-addressed store, hash-verified

179}
180
181const parseFormattedInput = (input, format, utc, dayjs) => {
182 try {
183 if (['x', 'X'].indexOf(format) > -1) return new Date((format === 'X' ? 1000 : 1) * input)
184 const parser = makeParser(format)
185 const {
186 year, month, day, hours, minutes, seconds, milliseconds, zone, week
187 } = parser(input)
188 const now = new Date()
189 const d = day || ((!year && !month) ? now.getDate() : 1)
190 const y = year || now.getFullYear()
191 let M = 0
192 if (!(year && !month)) {
193 M = month > 0 ? month - 1 : now.getMonth()
194 }
195 const h = hours || 0
196 const m = minutes || 0
197 const s = seconds || 0
198 const ms = milliseconds || 0
199 if (zone) {
200 return new Date(Date.UTC(y, M, d, h, m, s, ms + (zone.offset * 60 * 1000)))
201 }
202 if (utc) {
203 return new Date(Date.UTC(y, M, d, h, m, s, ms))
204 }
205 let newDate
206 newDate = new Date(y, M, d, h, m, s, ms)
207 if (week) {
208 newDate = dayjs(newDate).week(week).toDate()
209 }
210 return newDate
211 } catch (e) {
212 return new Date('') // Invalid Date
213 }
214}
215
216
217export default (o, C, d) => {

Callers 1

index.jsFile · 0.85

Calls 5

makeParserFunction · 0.85
dayjsFunction · 0.85
getMonthMethod · 0.80
toDateMethod · 0.80
weekMethod · 0.80

Tested by

no test coverage detected