Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 新的数据格式计算倒计时
- *
- * @param courseNew
- * @return CountDownDto
- */
- public static CountDownDto calculateSeries(CourseNew courseNew) {
- CountDownDto countDownDto = new CountDownDto();
- if (courseNew == null) {
- return countDownDto;
- }
- // 需要在拿到数据的时候塞进去本地的时间
- Long localCurTime = courseNew.getLocalTime();
- Long serverCurTime = courseNew.getCurrentTime();
- int lastIndex = courseNew.getCourseDetailDtos().size() - 1;
- int i = 0;
- for (CourseResNew.CourseOutlineDto outline : courseNew.getCourseDetailDtos()) {
- Long courseStartTime = outline.getStartTime();
- /** 开始倒计时的时间点 **/
- Long startCountDownTime = new Date().getTime();
- // 开课剩余时间
- Long limitTime = courseStartTime - serverCurTime - (startCountDownTime - localCurTime);
- if (serverCurTime < courseStartTime && limitTime > 0) {// 有课次还未开课,返回倒计时数据
- countDownDto.setIndex(i);
- countDownDto.setStatus(CountDownDto.COUNTDOWN);
- countDownDto.setData(calculateBylimitTime(limitTime));
- break;
- }
- if (outline.getEndTime() - courseNew.getCurrentTime() > System.currentTimeMillis() - courseNew
- .getLocalTime()) {// 直播中
- countDownDto.setIndex(i);
- countDownDto.setStatus(CountDownDto.LIVEING);
- break;
- } else {// 已结束
- if (i == lastIndex) {// 最后一项
- countDownDto.setIndex(i);
- countDownDto.setStatus(CountDownDto.END);
- }
- }
- i++;
- }
- return countDownDto;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement