<commit_before>// @flow
import type { DayText, Lesson, LessonTime } from 'types/modules';

// Converts a 24-hour format time string to an index.
// Each index corresponds to one cell of each timetable row.
// Each row may not start from index 0, it depends on the config's starting time.
// 0000 -> 0, 0030 -> 1, 0100 -> 2, ...
export function convertTimeToIndex(time: LessonTime): number {
  const hour: number = parseInt(time.substring(0, 2), 10);
  const minute: string = time.substring(2);
  // eslint-disable-next-line quote-props
  return hour * 2 + { '00': 0, '30': 1, '59': 2 }[minute];
}

// Reverse of convertTimeToIndex.<commit_msg>Fix timetable crashing on invalid timings (#1043)<commit_after>// @flow
import type { DayText, Lesson, LessonTime } from 'types/modules';

// Converts a 24-hour format time string to an index.
// Each index corresponds to one cell of each timetable row.
// Each row may not start from index 0, it depends on the config's starting time.
// 0000 -> 0, 0030 -> 1, 0100 -> 2, ...
export function convertTimeToIndex(time: LessonTime): number {
  const hour = parseInt(time.substring(0, 2), 10);
  const minute = parseInt(time.substring(2), 10);

  // TODO: Expose incorrect offsets to user via UI
  // Currently we round up in half hour blocks, but the actual time is not shown
  let minuteOffset;
  if (minute === 0) {
    minuteOffset = 0;
  } else if (minute <= 30) {
    minuteOffset = 1;
  } else {
    minuteOffset = 2;
  }

  return hour * 2 + minuteOffset;
}

// Reverse of convertTimeToIndex.
{'fraction_non_alphanumeric': 0.12280701754385964, 'fraction_numerical': 0.04483430799220273, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, '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': '1653317', 'n_tokens_mistral': 532, 'n_tokens_neox': 465, 'n_words': 193}