<commit_before>(function (window, document) {
  'use strict';

  var MINUTE = 60000
  var HOUR = MINUTE * 60
  var DAY = HOUR * 24
  var WEEK = DAY * 7
  var MONTH = DAY * 30
  var YEAR = DAY * 365
  var BASE_URL = 'https://my.cushionapp.com'
  var AVAILABLE = 'available'
  var UNAVAILABLE = 'unavailable'
  var SOON = 'soon'

  window.Availability = function (opts) {
    this.baseUrl = BASE_URL
    this.renderer = function noop () {}

    if (opts !== null && typeof opts === 'object') {
      if (opts.user) this.user = opts.user
      if (opts.renderer) this.renderer = opts.renderer
      if (opts.baseUrl) this.baseUrl = opts.baseUrl
    } else {
      this.user = opts
    }

    if (!this.user) throw('Must specify user')
  }

  Availability.prototype.render = function () {
    this.request()
  }

  Availability.prototype.request = function () {
    var xhr = new XMLHttpRequest()
    xhr.addEventListener('load', onLoad(this.renderer.bind(this)))
    xhr.addEventListener('error', onError)
    xhr.open('GET', this.baseUrl + '/api/v1/users/' + this.user + '/availability')
    xhr.send()
  }

  function parseDate (date) {
    date = date.split('-')

    var year = parseInt(date[0])
    var month = parseInt(date[1]) - 1
    var day = parseInt(date[2])

    return new Date(year, month, day)
  }

  function onLoad (fn) {
    return function () {
      if (this.status !== 200) return onError(this.status)
      var data = JSON.parse(this.response)

      if (null === data.availability) return fn(null, 0)

      var date = parseDate(data.availability.available_on)
      var hours = data.availability.hours_per_week
      var availability = Availability.utils.availability(date)

      return fn(availability, date, hours)
    }
  }

  function onError (e) {
    console.log('Error: ', e)
  }

  Availability.utils = {}

  Availability.utils.availability = function (date) {
    var diff = date - Date.now()
    if (date && diff < MONTH) return AVAILABLE
    if (date && diff < YEAR) return SOON
    return UNAVAILABLE
  }

  Availability.utils.monthAbbr = function (date) {
    return this.month(date).slice(0,3)
  }

  Availability.utils.month = function (date) {
    switch (date.getMonth()) {
    case 0:  return 'January'
    case 1:  return 'February'
    case 2:  return 'March'
    case 3:  return 'April'
    case 4:  return 'May'
    case 5:  return 'June'
    case 6:  return 'July'
    case 7:  return 'August'
    case 8:  return 'September'
    case 9:  return 'October'
    case 10: return 'November'
    case 11: return 'December'
    }
  }

  function merge (a, b) {<commit_msg>Improved abbreviations for shorter months that are weird abbreviated, like "Mar"<commit_after>(function (window, document) {
  'use strict';

  var MINUTE = 60000
  var HOUR = MINUTE * 60
  var DAY = HOUR * 24
  var WEEK = DAY * 7
  var MONTH = DAY * 30
  var YEAR = DAY * 365
  var BASE_URL = 'https://my.cushionapp.com'
  var AVAILABLE = 'available'
  var UNAVAILABLE = 'unavailable'
  var SOON = 'soon'

  window.Availability = function (opts) {
    this.baseUrl = BASE_URL
    this.renderer = function noop () {}

    if (opts !== null && typeof opts === 'object') {
      if (opts.user) this.user = opts.user
      if (opts.renderer) this.renderer = opts.renderer
      if (opts.baseUrl) this.baseUrl = opts.baseUrl
    } else {
      this.user = opts
    }

    if (!this.user) throw('Must specify user')
  }

  Availability.prototype.render = function () {
    this.request()
  }

  Availability.prototype.request = function () {
    var xhr = new XMLHttpRequest()
    xhr.addEventListener('load', onLoad(this.renderer.bind(this)))
    xhr.addEventListener('error', onError)
    xhr.open('GET', this.baseUrl + '/api/v1/users/' + this.user + '/availability')
    xhr.send()
  }

  function parseDate (date) {
    date = date.split('-')

    var year = parseInt(date[0])
    var month = parseInt(date[1]) - 1
    var day = parseInt(date[2])

    return new Date(year, month, day)
  }

  function onLoad (fn) {
    return function () {
      if (this.status !== 200) return onError(this.status)
      var data = JSON.parse(this.response)

      if (null === data.availability) return fn(null, 0)

      var date = parseDate(data.availability.available_on)
      var hours = data.availability.hours_per_week
      var availability = Availability.utils.availability(date)

      return fn(availability, date, hours)
    }
  }

  function onError (e) {
    console.log('Error: ', e)
  }

  Availability.utils = {}

  Availability.utils.availability = function (date) {
    var diff = date - Date.now()
    if (date && diff < MONTH) return AVAILABLE
    if (date && diff < YEAR) return SOON
    return UNAVAILABLE
  }

  Availability.utils.monthAbbr = function (date) {
    switch (date.getMonth()) {
    case 0:  return 'Jan'
    case 1:  return 'Feb'
    case 2:  return 'March'
    case 3:  return 'April'
    case 4:  return 'May'
    case 5:  return 'June'
    case 6:  return 'July'
    case 7:  return 'Aug'
    case 8:  return 'Sept'
    case 9:  return 'Oct'
    case 10: return 'Nov'
    case 11: return 'Dec'
    }
  }

  Availability.utils.month = function (date) {
    switch (date.getMonth()) {
    case 0:  return 'January'
    case 1:  return 'February'
    case 2:  return 'March'
    case 3:  return 'April'
    case 4:  return 'May'
    case 5:  return 'June'
    case 6:  return 'July'
    case 7:  return 'August'
    case 8:  return 'September'
    case 9:  return 'October'
    case 10: return 'November'
    case 11: return 'December'
    }
  }

  function merge (a, b) {
{'fraction_non_alphanumeric': 0.12896896182661435, 'fraction_numerical': 0.01641098822689975, 'mean_word_length': 2.7034346103038307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3263132', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1839, 'n_words': 526}