<commit_before>angular.module('focus.services')
.factory('TrainingProgram', function(ngdb) {
  var programsRepository = ngdb.getRepository('newPrograms');

  return {

    getPrograms: function() {
      return programsRepository.get();
    },

    addProgram: function(program) {
      return programsRepository.add(program);
    },

    clear: function() {
      programsRepository.delete();
    },

    updateProgram: function(program, id) {
      programsRepository.setBy({'id': id}).getOne;
      return programsRepository.update(program);
    },

    deleteProgram: function(id) {
      programsRepository.setBy({'id': id}).getOne;
      return programsRepository.delete();
    },

    addTimes: function(checked, frequency, duration) {
      var days = {
        'mon': 'mandag',
        'tue': 'tirsdag',
        'wed': 'onsdag',
        'thu': 'torsdag',
        'fri': 'fredag',
        'sat': 'lørdag',
        'sun': 'søndag'
      };

      var times = [];

      for (var i = 0; i < duration; i++) {
        for (var day in checked) {

          // If the day in the current week is checked
          if (checked.hasOwnProperty(day) && checked[day]) {

            var time;
            var day = moment().startOf('week').day(days[day]);

            // If the day this week has passed, push a date to a new week at the end
            if (i == 0 && moment().date() > day.date()) {
              time = day.add(duration * 7, 'days');
            }

            else {
              // Add a week
              time = day.add(i * 7, 'days');
            }
            times.push({
              time: time,
              finished: false
            });

          }
        }
      }

      return times.sort(function(a, b) {
        return a.unix() - b.unix();
      });

<commit_msg>Sort times array on the right attribute<commit_after>angular.module('focus.services')
.factory('TrainingProgram', function(ngdb) {
  var programsRepository = ngdb.getRepository('newPrograms');

  return {

    getPrograms: function() {
      return programsRepository.get();
    },

    addProgram: function(program) {
      return programsRepository.add(program);
    },

    clear: function() {
      programsRepository.delete();
    },

    updateProgram: function(program, id) {
      programsRepository.setBy({'id': id}).getOne;
      return programsRepository.update(program);
    },

    deleteProgram: function(id) {
      programsRepository.setBy({'id': id}).getOne;
      return programsRepository.delete();
    },

    addTimes: function(checked, frequency, duration) {
      var days = {
        'mon': 'mandag',
        'tue': 'tirsdag',
        'wed': 'onsdag',
        'thu': 'torsdag',
        'fri': 'fredag',
        'sat': 'lørdag',
        'sun': 'søndag'
      };

      var times = [];

      for (var i = 0; i < duration; i++) {
        for (var day in checked) {

          // If the day in the current week is checked
          if (checked.hasOwnProperty(day) && checked[day]) {

            var time;
            var day = moment().startOf('week').day(days[day]);

            // If the day this week has passed, push a date to a new week at the end
            if (i == 0 && moment().date() > day.date()) {
              time = day.add(duration * 7, 'days');
            }

            else {
              // Add a week
              time = day.add(i * 7, 'days');
            }
            times.push({
              time: time,
              finished: false
            });

          }
        }
      }

      return times.sort(function(a, b) {
        return a.time.unix() - b.time.unix();
      });


{'fraction_non_alphanumeric': 0.14427312775330398, 'fraction_numerical': 0.0022026431718061676, 'mean_word_length': 1.8140975987606507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1061899', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1041, 'n_words': 260}