andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 306 forks source link

Using `date.get('<weekday>', { future: true })` returns the next next <weekday>. #609

Closed alFReD-NSH closed 6 years ago

alFReD-NSH commented 7 years ago
const { Date } = require('sugar-date');
const date = new Date('14 aug 2017');
date.get('Saturday') // -> SugarChainable { raw: 2017-08-11T22:00:00.000Z }

It should instead return 5th August, not 12th. I can't reproduce it on other dates though.

andrewplummer commented 6 years ago

Sorry to be so late on this one... this one's a little mixed up though... considering you were expecting the date to be in the past I think you mean:

const { Date } = require('sugar-date');
const date = new Date('14 aug 2017');
date.get('Saturday'); // Case 1
date.get('Saturday', { past: true }); // Case 2

As you had it in case 1, I am showing that it returns 2017-08-19, which is expected. However case 2 is also returning 2017-08-19 which is a bug (#620). In any case this would be using past not future as the title of this ticket. In any case I've fixed the bug, so I'm going to close this one as a duplicate. Please feel free to re-open if there's some other aspect of this issue I'm missing... Thanks!