<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      LocalTime 持續時長計算

      public class DurationUtil {
          private static final Logger log = LoggerFactory.getLogger(DurationUtil.class);
      
          public static double toHours(Temporal start, Temporal end) {
              long minutes = Duration.between(start, end).toMinutes();
              long hours = minutes / 60;
              double v = (minutes % 60) / 60D;
              return v + hours;
          }
      
      
          /**
           * 24小時內 兩個時間段的重合區間
           * <pre>
           *     public static void main(String[] args) {
           *         {
           *             LocalTime formatStart = LocalTime.of(1, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(21, 0);
           *             LocalTime compareEnd = LocalTime.of(8, 0);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 180 current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(21, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(21, 0);
           *             LocalTime compareEnd = LocalTime.of(8, 3);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 3 current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(21, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(20, 56);
           *             LocalTime compareEnd = LocalTime.of(8, 3);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 7 current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(4, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(20, 56);
           *             LocalTime compareEnd = LocalTime.of(8, 3);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout  current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(21, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(20, 30);
           *             LocalTime compareEnd = LocalTime.of(4, 0);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 30 current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(21, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(21, 30);
           *             LocalTime compareEnd = LocalTime.of(4, 0);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 0 current is " + v);
           *         }
           *         {
           *             LocalTime formatStart = LocalTime.of(21, 0);
           *             LocalTime formatEnd = LocalTime.of(8, 0);
           *             LocalTime compareStart = LocalTime.of(20, 30);
           *             LocalTime compareEnd = LocalTime.of(20, 50);
           *             double v = toMillis(formatStart, formatEnd, compareStart, compareEnd) / 1000 / 60;
           *             System.out.println("shout 20 current is " + v);
           *         }
           *     }
           * </pre>
           */
          public static long toMillis(LocalTime formatStart, LocalTime formatEnd, LocalTime compareStart, LocalTime compareEnd) {
              List<LocalTimeDuration> build = LocalTimeDuration.build(formatStart, formatEnd);
              LocalTimeDuration formatMin = build.get(0);
              LocalTimeDuration formatMax = build.get(1);
              List<LocalTimeDuration> compares = LocalTimeDuration.build(compareStart, compareEnd);
              long result = 0;
              for (LocalTimeDuration compare : compares) {
                  result += toMillis(formatMin, formatMax, compare);
              }
              return result;
          }
      
          private static long toMillis(LocalTimeDuration min, LocalTimeDuration max, LocalTimeDuration compare) {
              if (compare == LocalTimeDuration.empty) {
                  return 0;
              }
              LocalTime start = compare.start;
              LocalTime end = compare.end;
              long result = 0;
              if (min != LocalTimeDuration.empty) {
                  if (start.isBefore(min.start)) {
                      if (end.isBefore(min.start)) {
                          return Duration.between(start, end).toMillis();
                      } else {
                          result += Duration.between(start, min.start).toMillis();
                          start = min.end;
                      }
                  }
                  if (min.isIn(start)) {
                      start = min.end;
                  }
              }
      
              if (start.isAfter(end)) {
                  return result;
              }
              if (start.isBefore(max.start)) {
                  if (end.isBefore(max.start)) {
                      return result + Duration.between(start, end).toMillis();
                  } else if (max.isIn(end)) {
                      return result + Duration.between(start, max.start).toMillis();
                  } else {
                      result += Duration.between(start, max.start).toMillis();
                      start = max.end;
                  }
              } else if (max.isIn(start)) {
                  if (end.isBefore(max.end)) {
                      return result;
                  } else {
                      return result + Duration.between(max.end, end).toMillis();
                  }
              } else {
                  return result + Duration.between(start, end).toMillis();
              }
              if (start.isAfter(end)) {
                  return result;
              }
              return result + Duration.between(start, end).toMillis();
          }
      
      
          /**
           * eg: start-> 21:00 end -> 08:00 checkTime -> 22:00 result is true
           * eg: start-> 21:00 end -> 08:00 checkTime -> 21:00 result is true
           * eg: start-> 21:00 end -> 08:00 checkTime -> 08:00 result is true
           * eg: start-> 21:00 end -> 08:00 checkTime -> 04:00 result is true
           * eg: start-> 21:00 end -> 08:00 checkTime -> 08:30 result is false
           * eg: start-> 08:00 end -> 12:00 checkTime -> 08:30 result is true
           * eg: start-> 08:00 end -> 12:00 checkTime -> 11:30 result is true
           * eg: start-> 08:00 end -> 16:00 checkTime -> 13:30 result is true
           * eg: start-> 08:00 end -> 16:00 checkTime -> 17:30 result is false
           */
      
          public static boolean timeInDuration(LocalTime start, LocalTime end, LocalTime time) {
              if (log.isDebugEnabled()) {
                  log.debug("start [{}] end [{}] time[{}]", start, end, time);
              }
              List<LocalTimeDuration> durations = LocalTimeDuration.build(start, end);
              for (LocalTimeDuration duration : durations) {
                  if (duration == LocalTimeDuration.empty) {
                      continue;
                  }
                  if (duration.isIn(time)) {
                      return true;
                  }
              }
              return false;
          }
      
          private static class LocalTimeDuration {
              private static final LocalTimeDuration empty = new LocalTimeDuration(null, null);
      
              public final LocalTime start;
              public final LocalTime end;
      
              public LocalTimeDuration(LocalTime start, LocalTime end) {
                  this.start = start;
                  this.end = end;
              }
      
              public static LocalTimeDuration of(LocalTime start, LocalTime end) {
                  return new LocalTimeDuration(start, end);
              }
      
              public static LocalTimeDuration max(LocalTime time) {
                  return new LocalTimeDuration(time, LocalTime.MAX);
              }
      
              public static LocalTimeDuration min(LocalTime time) {
                  return new LocalTimeDuration(LocalTime.MIN, time);
              }
      
              public static List<LocalTimeDuration> build(LocalTime start, LocalTime end) {
                  if (start.isAfter(end)) {
                      return Arrays.asList(min(end), max(start));
                  }
                  return Arrays.asList(empty, of(start, end));
              }
      
              /**
               * 全閉
               */
              public boolean isIn(LocalTime time) {
                  //return start.isBefore(time) && end.isAfter(time);
                  return time.equals(start) || (start.isBefore(time) && end.isAfter(time)) || end.equals(time);
              }
      
              public String toString() {
                  if (start != null && end != null) {
                      return start + "\t" + end;
                  }
                  return "";
              }
          }
      }
      
      posted @ 2023-06-09 15:53  _Y_h  閱讀(59)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产特级毛片aaaaaa毛片| 久久日韩精品一区二区五区| 国产尤物精品自在拍视频首页| 老司机久久99久久精品播放免费 | 国产高清小视频一区二区| 国产成人精品电影在线观看| 亚洲乱女色熟一区二区三区| 四虎国产精品永久在线下载| 中文字幕日韩精品人妻| 国产最新AV在线播放不卡| 亚洲国产精品一区二区久| 国产高清av首播原创麻豆| 色猫咪av在线观看| 欧洲精品码一区二区三区| 巨胸爆乳美女露双奶头挤奶| 日本东京热不卡一区二区| 野外做受三级视频| 成人免费AA片在线观看| 国产最大的福利精品自拍| 亚洲韩国精品无码一区二区三区 | 江达县| 夜夜嗨久久人成在日日夜夜| 国产精品久久中文字幕| 日韩精品区一区二区三vr| 老司机亚洲精品一区二区| 亚洲中文字幕第一页在线| 精品人妻午夜福利一区二区| 下面一进一出好爽视频| 国产熟女精品一区二区三区| 欧美激情一区二区三区成人| 欧美巨大极度另类| 熟女视频一区二区三区嫩草| 色欲AV无码一区二区人妻| 国产区一区二区现看视频| 午夜福利在线观看6080| 国产不卡av一区二区| 亚洲第一二三区日韩国产| 午夜视频免费试看| 视频一区视频二区在线视频| 平原县| 色欲综合久久中文字幕网|