andrewplummer / Sugar

A Javascript library for working with native objects.

Home Page:https://sugarjs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"end of [unit]" does not work as expected

dsyrstad opened this issue · comments

I'm using Sugar Date 2.0.4. Given the following code:

console.log("now: " + Sugar.Date.create("now"));
console.log("end of year: " + Sugar.Date.create("end of year"));
console.log("end of month: " + Sugar.Date.create("end of month"));
console.log("end of week: " + Sugar.Date.create("end of week"));
console.log("end of this year: " + Sugar.Date.create("end of this year"));
console.log("end of this month: " + Sugar.Date.create("end of this month"));
console.log("end of this week: " + Sugar.Date.create("end of this week"));

I get:

now: Thu Jun 28 2018 10:53:26 GMT-0500 (Central Daylight Time)
paper-sugar-date-picker.html:60 end of year: Tue Dec 31 **2019** 23:59:59 GMT-0600 (Central Standard Time)
paper-sugar-date-picker.html:61 end of month: Tue **Jul 31** 2018 23:59:59 GMT-0500 (Central Daylight Time)
paper-sugar-date-picker.html:62 end of week: Sat **Jul 07** 2018 23:59:59 GMT-0500 (Central Daylight Time)
paper-sugar-date-picker.html:63 end of this year: Mon Dec 31 2018 23:59:59 GMT-0600 (Central Standard Time)
paper-sugar-date-picker.html:64 end of this month: Sat Jun 30 2018 23:59:59 GMT-0500 (Central Daylight Time)
paper-sugar-date-picker.html:65 end of this week: Sat Jun 30 2018 23:59:59 GMT-0500 (Central Daylight Time)

You can see the date returned is one unit beyond what one would expect. As a native English speaker, I would take "end of year", "end of month", or "end of week" to mean 2018-12-31, 2018-06-30, and 2018-06-30 respectively given the current date of 2018-06-28 - not one more unit beyond that. You can see that "end of this [unit]" works correctly. "end of [unit]" should just be a shortened form.

This can be reproduced on the input field of https://sugarjs.com/dates/#/Parsing.

Also, supporting "year end" and "month end" (or "year-end"/"month-end") as aliases for "end of year" and "end of month" would be nice, but not exactly germane to this issue.

This one should be considered a bug. end of the year returns the correct dates and end of year should do the same... will look into this one.