Skip to content

Instantly share code, notes, and snippets.

@mdarby
Created December 29, 2011 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdarby/1534381 to your computer and use it in GitHub Desktop.
Save mdarby/1534381 to your computer and use it in GitHub Desktop.
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()
@isaacsanders
Copy link

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