Skip to content

Instantly share code, notes, and snippets.

@benbabics
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbabics/8702822 to your computer and use it in GitHub Desktop.
Save benbabics/8702822 to your computer and use it in GitHub Desktop.
selected_tags = @collection.filter (model) ->
# get data
is_client = model.get 'int_is_client'
last_posted = model.get 'dtm_last_posted'
# get morning time
morning = new Date()
morning.setHours 0
morning.setMinutes 0
morning.setSeconds 0
morning = morning.getTime()
# get midnight time
midnight = new Date()
midnight.setHours 24
midnight.setMinutes 0
midnight.setSeconds 0
midnight = midnight.getTime()
# get posted_time's time
posted_time = new Date( last_posted ).getTime()
# is this a selected tag?
is_client = is_client is 1 or is_client is true
# has this tag already been sent a message?
is_unsent = last_posted is undefined or last_posted is null
# is the posted_time on the tag less than midnight tonight?
is_unsent = morning <= posted_time <= midnight unless is_unsent
# return if this is a selected tag from today
is_client && is_unsent
@benbabics
Copy link
Author

This borders on ludicrous that "int_is_client" can either be of type boolean or number, and that 'dtm_last_posted' can be of type undefined, null or a string.

@craiglabenz
Copy link

It exceeds ludicrosity. There's an existing function on the PeopleClient model in JS that handles all 4 edge cases, and it's pure madness. I literally feel your pain.

@benbabics
Copy link
Author

This now accounts for morning too. :(

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