Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
someFunction: (date) ->
startOfMonth = date.beginningOfMonth()
endOfMonth = date.endOfMonth()
console.log startOfMonth.format('{MM}-{DD}-{YYYY}')
console.log endOfMonth.format('{MM}-{DD}-{YYYY}')
console.log '---'
# I call someFunction() with the SugarJS Date objects representing "12-09-2011" and "01-09-2012" and get this in the console:
# 12-31-2011
# 12-31-2011
# ---
# 01-31-2012
# 01-31-2012
# ---
# Why is `endOfMonth` clobbering `startOfMonth`?
# To get around this, I had to do:
startOfMonth = Date.create(date.format('{MM}-{DD}-{YYYY}')).beginningOfMonth()
endOfMonth = Date.create(date.format('{MM}-{DD}-{YYYY}')).endOfMonth()

This comment has been minimized.

Copy link

@isaacsanders isaacsanders commented Dec 29, 2011

Maybe it is because you are calling it on the date object, and Sugar could be overwriting it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment