timeToIndex function

int timeToIndex(
  1. int hour
)

将时间的小时转化为时辰的索引

hour 当前时间的小时数 返回 时辰的索引

Implementation

int timeToIndex(int hour) {
  if (hour == 0) {
    // 00:00~01:00 为早子时
    return 0;
  }

  if (hour == 23) {
    // 23:00~00:00 为晚子时
    return 12;
  }

  return ((hour + 1) / 2).floor();
}