<commit_before>_ = require 'underscore'
Backbone = require 'backbone'
moment = require 'moment'

UNIT_MAP =
  'months': 'mos'
  'days': 'days'
  'hours': 'hrs'
  'minutes': 'min'
  'seconds': 'sec'

module.exports = class ClockView extends Backbone.View

  modelName: 'Auction'

  initialize: ({ @closedText, @modelName }) ->
    @closedText ?= 'Online Bidding Closed'

  start: ->
    @model.calculateOffsetTimes
      success: =>
        @model.on('change:clockState', ->
          clearInterval @interval
          location?.reload()
        )
        @render()

  render: =>
    switch @model.get('clockState')
      when 'preview'
        @$('.clock-header').html "#{@modelName} opens in:"
        @toDate = @model.get 'offsetStartAtMoment'
      when 'open'
        @$('.clock-header').html "#{@modelName} closes in:"
        @toDate = @model.get 'offsetEndAtMoment'
      when 'closed'
        @$el.html "<div class='clock-header clock-closed'>#{@closedText}</div>"
        return
    @renderClock()
    @interval = setInterval @renderClock, 1000

  renderClock: =>
    @model.updateState()
    @$('.clock-value').html _.compact((for unit, label of UNIT_MAP
      diff = moment.duration(@toDate?.diff(moment()))[unit]()

      # Don't display '00' if we have 0 months
      if diff < 1 and unit in ['months']
        false
      else
        """
          <li>
            #{if diff < 10 then '0' + diff else diff}
            <small>#{label}</small>
          </li>
        """
    )).join '<li>:</li>'
<commit_msg>Clock start should have a callback<commit_after>_ = require 'underscore'
Backbone = require 'backbone'
moment = require 'moment'

UNIT_MAP =
  'months': 'mos'
  'days': 'days'
  'hours': 'hrs'
  'minutes': 'min'
  'seconds': 'sec'

module.exports = class ClockView extends Backbone.View

  modelName: 'Auction'

  initialize: ({ @closedText, @modelName }) ->
    @closedText ?= 'Online Bidding Closed'

  start: (callback = $.noop) ->
    @model.calculateOffsetTimes
      success: =>
        @model.on('change:clockState', ->
          clearInterval @interval
          location?.reload()
        )
        @render()
        callback()

  render: =>
    switch @model.get('clockState')
      when 'preview'
        @$('.clock-header').html "#{@modelName} opens in:"
        @toDate = @model.get 'offsetStartAtMoment'
      when 'open'
        @$('.clock-header').html "#{@modelName} closes in:"
        @toDate = @model.get 'offsetEndAtMoment'
      when 'closed'
        @$el.html "<div class='clock-header clock-closed'>#{@closedText}</div>"
        return
    @renderClock()
    @interval = setInterval @renderClock, 1000

  renderClock: =>
    @model.updateState()
    @$('.clock-value').html _.compact((for unit, label of UNIT_MAP
      diff = moment.duration(@toDate?.diff(moment()))[unit]()

      # Don't display '00' if we have 0 months
      if diff < 1 and unit in ['months']
        false
      else
        """
          <li>
            #{if diff < 10 then '0' + diff else diff}
            <small>#{label}</small>
          </li>
        """
    )).join '<li>:</li>'

{'fraction_non_alphanumeric': 0.16387636831938185, 'fraction_numerical': 0.0070830650354153256, 'mean_word_length': 2.4560622914349275, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '7529727', 'n_tokens_mistral': 1015, 'n_tokens_neox': 975, 'n_words': 238}