-# FIXME adapt to new UI
-# class Time
-#   constructor: (@selector)->
-#     @str = @selector.val()
-#     parts = @str.split(":")
-#     @hour   = parseInt(parts[0])
-#     @minute = parseInt(parts[1])
+class Lale.DateTime
+  constructor: (date_field, time_field)->
+    @value = this.buildDate(date_field, time_field)
 
-#   lessThan: (other) ->
-#     if @hour < other.hour
-#       true
+  buildDate: (date_field, time_field)->
+    date = this.parseDate(date_field)
+    time = this.parseTime(time_field)
+    date.setHours(time['hours'])
+    date.setMinutes(time['minutes'])
+    date
 
-#     else if @hour == other.hour
-#       @minute <= other.minute
+  valid:->
+    @value instanceof Date
 
-#     else
-#       false
+  parseDate: (field)->
+    field.datetimepicker('getValue')
 
-#   update: (other) ->
-#     @selector.val(other.str)
+  parseTime: (field)->
+    if field.val()
+      parts = field.val().split(":")
+      h = parseInt(parts[0])
+      m = parseInt(parts[1])
+    else
+      h = 0
+      m = 0
+    { hours: h, minutes: m }
 
 ready = ->
 

      dayOfWeekStart: I18n.t('datepicker.day_of_week_start'),
      format:         I18n.t('datepicker.date_format'),
      minDate:        0,
      scrollMonth:    false
    });

    $('.xd_timepicker').datetimepicker({
      datepicker:     false,
      step:           15,
      format:         I18n.t('datepicker.time_format'),
      defaultTime:    '12:00'
    });

  showOrHideEndDate = ->
    type = $('#task_scheduling_type').val()
    if type == "between" 
      $('.at-element').hide()

    working_group = $('#task_working_group_id :selected').text()
    escaped_wg = working_group.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
    options = $(organizers).filter("optgroup[label='#{escaped_wg}']").html()
    if options
      $('#task_organizer_id').html(options)
      $('#task_organizer_id').parent().show()
