<commit_before>class @Gws_Schedule_Plan
  @diffOn: 0

  @renderForm: (opts = {})->
    $(".date").datetimepicker
      lang: "ja"
      timepicker: false
      format:'Y/m/d'
      closeOnDateSelect: true
      scrollInput: false
      maxDate: opts["maxDate"]
    $(".datetime").datetimepicker
      lang: "ja"
      roundTime: 'ceil'
      step: 30
      maxDate: opts["maxDate"]
    @relateDateForm()
    @relateDateTimeForm()

  @renderAlldayForm: ->
    @changeDateForm()
    $('#item_allday').change ->
      Gws_Schedule_Plan.changeDateValue()
      Gws_Schedule_Plan.changeDateForm()

  # @example
  #   2015/09/29 00:00 => 2015/09/29
  #   2015/09/29 => 2015/09/29 00:00
  @changeDateValue: ->
    if $('#item_allday').prop('checked')
      $('#item_start_on').val $('#item_start_at').val().replace(/ .*/, '')
      $('#item_end_on').val $('#item_end_at').val().replace(/ .*/, '')
    else
      stime = $('#item_start_at').val().replace(/.* /, '')
      etime = $('#item_end_at').val().replace(/.* /, '')
      stime = '00:00' if stime == '' && $('#item_start_on').val() != ''
      etime = '00:00' if etime == '' && $('#item_end_on').val() != ''
      $('#item_start_at').val $('#item_start_on').val() + " #{stime}"
      $('#item_end_at').val $('#item_end_on').val() + " #{etime}"

  @changeDateForm: ->
    if $('#item_allday').prop('checked')
      $('.dates-field').show()
      $('.datetimes-field').hide()
    else
      $('.dates-field').hide()
      $('.datetimes-field').show()

  @relateDateForm: (start_sel = '.date.start', end_sel = '.date.end') ->
    $("#{start_sel}, #{end_sel}").click ->
      Gws_Schedule_Plan.diffOn = Gws_Schedule_Plan.diffDates($(start_sel).val(), $(end_sel).val())
    $(start_sel).change ->
      start = $(start_sel).val()
      return unless start
      date = new Date()
      date.setTime((new Date(start)).getTime() + Gws_Schedule_Plan.diffOn)
      format = '%d/%02d/%02d'
      format = '%d/%02d/%02d %02d:%02d' if $(start_sel).hasClass('datetime')
      $(end_sel).val(sprintf(format, date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes()))

  @relateDateTimeForm: ->
    @relateDateForm('.datetime.start', '.datetime.end')

  @diffDates: (src, dst)->
    return 0 if !src || !dst
    diff = (new Date(dst)).getTime() - (new Date(src)).getTime();
    return 0 if diff < 0
    diff<commit_msg>[modify] gws/schedule: default end_at = start_at + 1.hour<commit_after>class @Gws_Schedule_Plan
  @diffOn: 0

  @renderForm: (opts = {})->
    $(".date").datetimepicker
      lang: "ja"
      timepicker: false
      format:'Y/m/d'
      closeOnDateSelect: true
      scrollInput: false
      maxDate: opts["maxDate"]
    $(".datetime").datetimepicker
      lang: "ja"
      roundTime: 'ceil'
      step: 30
      maxDate: opts["maxDate"]
    @relateDateForm()
    @relateDateTimeForm()

  @renderAlldayForm: ->
    @changeDateForm()
    $('#item_allday').change ->
      Gws_Schedule_Plan.changeDateValue()
      Gws_Schedule_Plan.changeDateForm()

  # @example
  #   2015/09/29 00:00 => 2015/09/29
  #   2015/09/29 => 2015/09/29 00:00
  @changeDateValue: ->
    if $('#item_allday').prop('checked')
      $('#item_start_on').val $('#item_start_at').val().replace(/ .*/, '')
      $('#item_end_on').val $('#item_end_at').val().replace(/ .*/, '')
    else
      stime = $('#item_start_at').val().replace(/.* /, '')
      etime = $('#item_end_at').val().replace(/.* /, '')
      stime = '00:00' if stime == '' && $('#item_start_on').val() != ''
      etime = '00:00' if etime == '' && $('#item_end_on').val() != ''
      $('#item_start_at').val $('#item_start_on').val() + " #{stime}"
      $('#item_end_at').val $('#item_end_on').val() + " #{etime}"

  @changeDateForm: ->
    if $('#item_allday').prop('checked')
      $('.dates-field').show()
      $('.datetimes-field').hide()
    else
      $('.dates-field').hide()
      $('.datetimes-field').show()

  @relateDateForm: (start_sel = '.date.start', end_sel = '.date.end') ->
    $("#{start_sel}, #{end_sel}").click ->
      Gws_Schedule_Plan.diffOn = Gws_Schedule_Plan.diffDates($(start_sel).val(), $(end_sel).val())
    $(start_sel).change ->
      start = $(start_sel).val()
      return unless start
      date = new Date()
      date.setTime((new Date(start)).getTime() + Gws_Schedule_Plan.diffOn)
      format = '%d/%02d/%02d'
      format = '%d/%02d/%02d %02d:%02d' if $(start_sel).hasClass('datetime')
      $(end_sel).val(sprintf(format, date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes()))

  @relateDateTimeForm: ->
    @relateDateForm('.datetime.start', '.datetime.end')

  @diffDates: (src, dst)->
    return 1000 * 60 * 60 if !src || !dst
    diff = (new Date(dst)).getTime() - (new Date(src)).getTime();
    return 0 if diff < 0
    diff
{'fraction_non_alphanumeric': 0.2228429546865301, 'fraction_numerical': 0.029381336643906478, 'mean_word_length': 3.103565365025467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3628626', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1697, 'n_words': 276}