The JavaScript object below has some past date value set. I need to calculate these values from the current date using JavaScript.
Right now the date values are manually set but they should be calculated automatically with JavaScript
For example the dates for Last Week
should take the start date of the current week and use the day before that as the end date
for Last Week
and then count 6 days before that to get the start date
for Last Week
.
How can I do this in JS and work in all browsers?
I am fine with using MomentJS is that is useful for this type of thing?
// Date Divider Date values for cocomparisoagainstt Tasks created_at DateTime
var dateRangeLabels = {
'Today': {
'start': new Date('2015-09-12T00:00:00'),
'end': new Date('2015-09-12T00:00:00'),
'dateFunc': 'inRange'
},
'Yesterday': {
'start': new Date('2015-09-11T00:00:00'),
'end': new Date('2015-09-11T00:00:00'),
'dateFunc': 'inRange'
},
'Earlier this Week': {
'start': new Date('2015-09-06T00:00:00'),
'end': new Date('2015-09-10T00:00:00'),
'dateFunc': 'inRange'
},
'Last Week': {
'start': new Date('2015-08-30T00:00:00'),
'end': new Date('2015-09-05T00:00:00'),
'dateFunc': 'inRange'
},
'A while Ago': {
'start': new Date('2010-08-30T00:00:00'),
'end': new Date('2015-07-31T00:00:00'),
'dateFunc': 'inRange'
},
'Last Month': {
'start': new Date('2015-08-01T00:00:00'),
'end': new Date('2015-08-31T00:00:00'),
'dateFunc': 'inRange'
},
'Earliar in the Month': {
'start': new Date('2015-08-30T00:00:00'),
'end': new Date('2015-09-05T00:00:00'),
'dateFunc': 'inRange'
},
'other': {
'start': new Date('2015-09-13T00:00:00'),
'end': new Date('2999-12-31T00:00:00'),
'dateFunc': 'inRange'
}
}
This calendar image visualizes the start
and end
dates I would need to get based on named duration value.
For last week
I would need to determine what the date was for the start
and end
of last week from todays date. In this example would be:
start date: 1/4/2016
and end date: 1/10/2016