Reputation: 476
I'm attempting to parse a date returned to me from amazons Lex chatbot API. Some example return formats are ( From the API docs https://developer.amazon.com/docs/custom-skills/slot-type-reference.html#date )
“next week”: 2015-W49
“this weekend”: 2015-W48-WE
“this month”: 2015-11
My particular case is "2017-W47-WE".
I've tried parsing it in a couple of ways, with no luck
Vanilla
var newDate = new Date(date) // Invalid date
MomentJS
moment(date)
moment(date, moment.ISO_8601).format('YYYY/MM/DD')
moment(date).format('YYYY-MM-DD')
None of which work, Does anyone have any idea how to correctly format this date? Thanks!
Upvotes: 0
Views: 164
Reputation: 4694
The -WE
part is abit strange. Even if you can correctly parsed it I have no idea what should be returned. Since weekend includes two days (Saturday and Sunday) so should it be an array of moment objects?
Anyway, you can get weekend alternatively like so
var SAT_OF_WEEK_47 = moment("2017-W47-WE".replace("WE","6"), "YYYY-[W]WW-E").format()
var SUN_OF_WEEK_47 = moment("2017-W47-WE".replace("WE","7"), "YYYY-[W]WW-E").format()
I explicitly declared the format and use E
1..7
as ISO day of week. Let me know if this is what you are trying to achieve.
Upvotes: 1