Calculate past dates from today in JavaScript
<p>The JavaScript object below has some past date value set.  I need to calculate these values from the current date using JavaScript.</p>

<p>Right now the date values are manually set but they should be calculated automatically with JavaScript</p>

<p>For example the dates for <code>Last Week</code> should take the start date of the current week and use the day before that as the <code>end date</code> for  <code>Last Week</code> and then count 6 days before that to get the <code>start date</code> for  <code>Last Week</code>.</p>

<p>How can I do this in JS and work in all browsers?</p>

<p>I am fine with using MomentJS is that is useful for this type of thing?</p>

<pre><code>// 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'
    }
}
</code></pre>

<hr>

<p>This calendar image visualizes the <code>start</code> and <code>end</code> dates I would need to get based on named duration value.</p>

<p>For <code>last week</code> I would need to determine what the date was for the <code>start</code> and <code>end</code> of last week from todays date.  In this example would be:<br>
<code>start date: 1/4/2016</code> and <code>end date: 1/10/2016</code></p>

<p><a href="https://i.stack.imgur.com/LEnDp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LEnDp.png" alt="enter image description here"></a></p>