Skip to content

Instantly share code, notes, and snippets.

@wildskyf
Created August 28, 2015 09:37
Show Gist options
  • Select an option

  • Save wildskyf/2c5dd2aca5a007dc0fb4 to your computer and use it in GitHub Desktop.

Select an option

Save wildskyf/2c5dd2aca5a007dc0fb4 to your computer and use it in GitHub Desktop.
A function to get Sunday
###
# input: "20150806XXXXXXXX"
# output "20150802"
###
getSunday = (date) ->
if typeof(date) isnt "string"
date = date.toString()
if date.length isnt 8
date = date.slice(0, 8)
tmp = new Date()
tmp.setYear(Number(date.slice(0,4)))
tmp.setMonth(Number(date.slice(4,6)) - 1)
tmp.setDate(Number(date.slice(6,8)))
tmp.setDate(tmp.getDate() - tmp.getDay())
sYear = tmp.getFullYear().toString()
sMonth = (tmp.getMonth() + 1).toString()
sDay = (tmp.getDate()).toString()
sunday = sYear + (if sMonth < 10 then "0" else "") + sMonth + (if sDay < 10 then "0" else "") + sDay
sunday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment