Skip to content

Instantly share code, notes, and snippets.

@raganwald
Forked from thejohnnybot/gist:3976278
Created October 29, 2012 21:33
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 raganwald/3976679 to your computer and use it in GitHub Desktop.
Save raganwald/3976679 to your computer and use it in GitHub Desktop.
Date Issue
class Store
constructor: () ->
@services = []
@reservations = []
@requests = []
class Service
constructor: (@name, @time) ->
class Request
constructor: (@date, @services) ->
class Reservation
constructor: (@start, @finish, @service) ->
store = new Store()
store.services.push(new Service("Corte", 30))
store.services.push(new Service("Manicura", 30))
request = new Request(new Date(), [store.services[0], store.services[1]])
store.requests.push(request)
# This is where it breaks
makeReservation = (request) ->
date = request.date
mins = request.date.getMinutes()
mins_offSet = 0
for service in request.services
date.setMinutes(mins + service.time + mins_offSet)
finish_date = new Date(date)
store.reservations.push(new Reservation(request.date, finish_date, service))
mins_offSet += service.time
makeReservation(request)
[first, second] = store.reservations
console.log first.finish instanceof Date and second.finish instanceof Date
console.log first.finish.getTime() isnt second.finish.getTime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment