Question: Suppose I have a function that returns the starting index (4) of the word 'world' in this HTML string:

```
<div>The world is round</div>

```

This function (outside of my control) works by using jQuery's `.text()` method. However, I need to use jQuery's `.html()` method for what I'm doing.

Using the existing index will give me the letter "n" from the span when using jQuery's `.html()` method. I need to alter this index to take account of additional HTML tags and nested HTML tags that might be in the div e.g.

```
<div><p><span class="highlight">The</span></p> world is round</div>

```

So, this code snippet would return a new index of 42 for the first letter of 'world'. How would I go about doing this? Many thanks!

UPDATE: The code snippet would return the index INCLUDING the tags. I'm not looking to strip the tags. Thanks!

Answer: 
Use the [moment.js](https://momentjscom.readthedocs.io/en/latest/) library for time and date management. 

```
import moment = require('moment');

const now = moment();

now.subtract(7, 'seconds'); // 7 seconds ago
now.subtract(7, 'days');    // 7 days and 7 seconds ago
now.subtract(7, 'months');  // 7 months, 7 days and 7 seconds ago
now.subtract(7, 'years');   // 7 years, 7 months, 7 days and 7 seconds ago
// because `now` has been mutated, it no longer represents the current time

```
This does not answer the question fully, but for anyone who is able to calculate the number of days by which they would like to offset an initial date then the following method will work: 

```
myDate.setUTCDate(myDate.getUTCDate() + offsetDays);

```

offsetDays can be positive or negative and the result will be correct for any given initial date with any given offset.