protected boolean periodicalIsFullyInPeriod(
     Date periodBeginDate, Date periodEndDate, K periodical) {
   return (periodical.getBeginDate().after(periodBeginDate)
           || DateUtils.isSameDay(periodical.getBeginDate(), periodBeginDate))
       && (periodical.getEndDate().before(periodEndDate)
           || (DateUtils.isSameDay(periodical.getEndDate(), periodEndDate)));
 }
  void checkIfSameDay() throws Exception {
    String startDateStr = "03/03/2011";
    String endDateStr = "03/03/2011";
    Date endDate = formatter.parse(endDateStr);

    boolean isSameDay;
    isSameDay =
        DateUtils.isSameDay(formatter.parse(beginningOfMonth), formatter.parse(startDateStr));
    System.out.println("==1==" + isSameDay);
    isSameDay = DateUtils.isSameDay(formatter.parse(yesterday), endDate);
    System.out.println("==2==" + isSameDay);

    isSameDay = DateUtils.isSameDay(formatter.parse(yesterday), formatter.parse(startDateStr));
    System.out.println("==3==" + isSameDay);
    isSameDay = DateUtils.isSameDay(formatter.parse(yesterday), endDate);
    System.out.println("==4==" + isSameDay);
  }
Exemplo n.º 3
0
 @Test
 public void testDaysAgo() {
   DateCriterion criterion = new DateCriterion().setDate(3);
   Date date = criterion.getDate();
   assertThat(date.getMinutes(), is(0));
   assertThat(date.getHours(), is(0));
   assertThat(DateUtils.isSameDay(date, DateUtils.addDays(new Date(), -3)), is(true));
 }
Exemplo n.º 4
0
 @Override
 public Cart getCurrent() {
   RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
   if (requestAttributes != null) {
     HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
     Principal principal =
         (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME);
     Member member = principal != null ? memberDao.find(principal.getId()) : null;
     if (member != null) {
       Cart cart = member.getCart();
       if (cart != null) {
         if (!cart.hasExpired()) {
           if (!DateUtils.isSameDay(cart.getModifyDate(), new Date())) {
             cart.setModifyDate(new Date());
             cartDao.merge(cart);
           }
           return cart;
         } else {
           cartDao.remove(cart);
         }
       }
     } else {
       String id = WebUtils.getCookie(request, Cart.ID_COOKIE_NAME);
       String key = WebUtils.getCookie(request, Cart.KEY_COOKIE_NAME);
       if (StringUtils.isNotEmpty(id)
           && StringUtils.isNumeric(id)
           && StringUtils.isNotEmpty(key)) {
         Cart cart = cartDao.find(Long.valueOf(id));
         if (cart != null && cart.getMember() == null && StringUtils.equals(cart.getKey(), key)) {
           if (!cart.hasExpired()) {
             if (!DateUtils.isSameDay(cart.getModifyDate(), new Date())) {
               cart.setModifyDate(new Date());
               cartDao.merge(cart);
             }
             return cart;
           } else {
             cartDao.remove(cart);
           }
         }
       }
     }
   }
   return null;
 }
Exemplo n.º 5
0
 public Cart getCurrent() {
   RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
   if (requestAttributes != null) {
     HttpServletRequest httpServletRequest =
         ((ServletRequestAttributes) requestAttributes).getRequest();
     Principal principal =
         (Principal) httpServletRequest.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME);
     Member member = principal != null ? (Member) this.memberDao.find(principal.getId()) : null;
     if (member != null) {
       Cart cart = member.getCart();
       if (cart != null) {
         if (!cart.hasExpired()) {
           if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) {
             cart.setUpdateDate(new Date());
             this.cartDao.merge(cart);
           }
           return cart;
         }
         this.cartDao.remove(cart);
       }
     } else {
       String cartIdString = CookieUtils.getCookie(httpServletRequest, "cartId");
       String cartKeyString = CookieUtils.getCookie(httpServletRequest, "cartKey");
       if ((StringUtils.isNotEmpty(cartIdString))
           && (StringUtils.isNumeric(cartIdString))
           && (StringUtils.isNotEmpty(cartKeyString))) {
         Cart cart = (Cart) this.cartDao.find(Long.valueOf(cartIdString));
         if ((cart != null)
             && (cart.getMember() == null)
             && (StringUtils.equals(cart.getKey(), cartKeyString))) {
           if (!cart.hasExpired()) {
             if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) {
               cart.setUpdateDate(new Date());
               this.cartDao.merge(cart);
             }
             return cart;
           }
           this.cartDao.remove(cart);
         }
       }
     }
   }
   return null;
 }
Exemplo n.º 6
0
 /**
  * 订课,订课后可在订课记录中查看
  *
  * @see LessonRecordAction#orderRecords()
  * @return
  */
 public String orderLesson() {
   xyxx.setId(sid);
   schedule.setId(id);
   Calendar c = Calendar.getInstance();
   int today = c.get(Calendar.DAY_OF_WEEK);
   if (today == Calendar.FRIDAY && c.get(Calendar.HOUR_OF_DAY) >= Constants.TIME_LINE) {
     schedule = commonService.getSchedule(schedule);
     c.add(Calendar.DATE, 1);
     if (org.apache.commons.lang.time.DateUtils.isSameDay(c.getTime(), schedule.getStart())) {
       msg = getText("周五" + Constants.TIME_LINE + "点之后不能预订周六的拓展课!");
       return INPUT;
     }
   }
   if (today == Calendar.SATURDAY && c.get(Calendar.HOUR_OF_DAY) >= Constants.TIME_LINE) {
     schedule = commonService.getSchedule(schedule);
     c.add(Calendar.DATE, 1);
     if (org.apache.commons.lang.time.DateUtils.isSameDay(c.getTime(), schedule.getStart())) {
       msg = getText("周六" + Constants.TIME_LINE + "点之后不能预订当周的拓展课!");
       return INPUT;
     }
   }
   if (commonService.getOrderLessonCountBySchedule(schedule) >= Constants.MAX_STUDENTS_IN_CLASS) {
     msg = getText("orderLesson.schedule.is.full", "本节拓展课已被订满!");
     return INPUT;
   }
   if (!commonService.canOrderLesson(schedule, xyxx)) {
     msg = getText("orderLesson.schedule.has.ordered", "您已经订过本节拓展课了!");
     return INPUT;
   } else {
     try {
       commonService.orderLesson(schedule, xyxx, fromType);
       schedule.setScheduleState(ScheduleStateDto.getCanOrder());
       result = SfDto.TRUE;
     } catch (Exception e) {
       e.printStackTrace();
       return INPUT;
     }
   }
   return SUCCESS;
 }
 private Date checkAndReturnDeadline(String deadLineParam, Result<ActionPlan> result) {
   Date deadLine = null;
   if (!Strings.isNullOrEmpty(deadLineParam)) {
     try {
       deadLine = RubyUtils.toDate(deadLineParam);
       Date today = new Date();
       if (deadLine != null
           && deadLine.before(today)
           && !org.apache.commons.lang.time.DateUtils.isSameDay(deadLine, today)) {
         result.addError(Result.Message.ofL10n("action_plans.date_cant_be_in_past"));
       }
     } catch (SonarException e) {
       result.addError(Result.Message.ofL10n("errors.is_not_valid", "date"));
     }
   }
   return deadLine;
 }
 /**
  * 取消订课记录
  *
  * @return
  */
 public String cancelOrder() {
   skjl.setId(id);
   skjl = commonService.getLessonRecord(skjl);
   Calendar now = Calendar.getInstance();
   // 系统当前时间加一天
   // now.add(Calendar.DATE, 1);
   // if (DateUtils.isSameDay(now.getTime(), skjl.getStartTime())
   // || now.getTime().compareTo(skjl.getStartTime()) >= 0) {
   if (DateUtils.isSameDay(now.getTime(), skjl.getStartTime())) {
     // 如果系统当前时间增加一天后,和订课的时间是同一天的话,则不能取消订课
     msg = getText("orderLesson.cancel.not.current.day", "您不能取消当天的订课!");
     return INPUT;
   } else {
     commonService.cancelOrderRecord(skjl, fromType);
     return SUCCESS;
   }
 }
Exemplo n.º 9
0
  private float getNbJoursForAbsence(DemandeAbsence absence) throws Exception {

    // nombre de jours d'écart entre datedeb et dateFin
    float nbJours =
        Days.daysBetween(new DateTime(absence.getDateDebut()), new DateTime(absence.getDateFin()))
            .getDays();
    nbJours += 1;

    if (absence.getDebutPM()) {
      nbJours -= 0.5;
    }
    if (absence.getFinAM()) {
      nbJours -= 0.5;
    }

    // recup des jours feries
    List<Date> joursFeries = null;
    try {
      joursFeries = calendarService.getJourFeries();
    } catch (Exception e) {
      throw new Exception(e.getMessage());
    }

    // les samedis et dimanche ne sont pas pris en compte
    // supprimer les jours feries
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(absence.getDateDebut());
    // gestion des dates différentes dans le cloud
    while (!DateUtils.isSameDay(calendar.getTime(), absence.getDateFin())) {
      // System.out.println("!!!! " + calendar.getTime() + ">" +
      // calendar.get(Calendar.DAY_OF_WEEK));
      if (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) {
        nbJours -= 1;
      }
      if (joursFeries.contains(calendar.getTime())) {
        nbJours -= 1;
      }
      calendar.add(Calendar.DATE, 1);
    }

    return nbJours;
  }
Exemplo n.º 10
0
  /**
   * 8、日期
   *
   * @throws ParseException
   */
  @Test
  public void test8() throws ParseException {
    // 生成Date对象
    Date date = DateUtils.parseDate("2010/01/01 11:22:33", new String[] {"yyyy/MM/dd HH:mm:ss"});

    // 10天后
    Date tenDaysAfter = DateUtils.addDays(date, 10); // => 2010/01/11
    // 11:22:33
    System.out.println(DateFormatUtils.format(tenDaysAfter, "yyyy/MM/dd HH:mm:ss"));

    // 前一个月
    Date prevMonth = DateUtils.addMonths(date, -1); // => 2009/12/01
    // 11:22:33
    System.out.println(DateFormatUtils.format(prevMonth, "yyyy/MM/dd HH:mm:ss"));

    // 判断是否是同一天
    Date date1 = DateUtils.parseDate("2010/01/01 11:22:33", new String[] {"yyyy/MM/dd HH:mm:ss"});
    Date date2 = DateUtils.parseDate("2010/01/01 22:33:44", new String[] {"yyyy/MM/dd HH:mm:ss"});
    System.out.println(DateUtils.isSameDay(date1, date2)); // true

    // 日期格式化
    System.out.println(DateFormatUtils.format(new Date(), "yyyy/MM/dd HH:mm:ss"));
  }
Exemplo n.º 11
0
  public void start() {
    log.info("Start cpm stats process task.");

    // 记录会被Suspend的Campaign
    Set<Integer> suspendCampaignIds = new TreeSet<Integer>();
    // 记录会被预警的Campaign
    Set<Integer> warningCampaignIds = new TreeSet<Integer>();
    // 记录被修改的Campaign
    List<Integer> modifiedCampaignIds = new ArrayList<Integer>();
    // 统计每个广告主的实时余额
    Map<Integer, Long> advertiserBalances = new HashMap<Integer, Long>();

    Date today = DateTimeUtil.getCurrentDateDay();
    Date yesterday = DateTimeUtil.subtractDays(today, 1);

    List<AdCampaign> campaigns = adCampaignService.listCampaignsBidType(BidTypeEnum.CPM);
    for (AdCampaign campaign : campaigns) {
      modifiedCampaignIds.add(campaign.getId());

      AdCampaignDailyStatistic stats =
          statsCampaignService.sumCampStatsByCampIdWithRangeDate(campaign.getId(), today);
      AdCampBudget campBudget = adCampaignBudgetService.getDayCampBudget(campaign.getId(), today);
      int comm = (stats.getCpmTotalCommission().multiply(new BigDecimal(100))).intValue();
      campBudget.setBudgetDay(comm);
      campBudget.setBudgetTotal(campBudget.getBudgetTotal() + comm);
      if (!DateUtils.isSameDay(today, campBudget.getDateDay())) {
        // Update total budget if not the same day
        campBudget.setDateDay(today);
        AdCampaignDailyStatistic statsPrev =
            statsCampaignService.sumCampStatsByCampIdWithRangeDate(campaign.getId(), yesterday);
        int commPrev = (statsPrev.getCpmTotalCommission().multiply(new BigDecimal(100))).intValue();
        campBudget.setBudgetTotal(campBudget.getBudgetTotal() + commPrev);
        adCampaignBudgetService.updateCampBudget(campBudget);
      }

      if (campBudget.isExceedBudget()) {
        // 预算不足
        log.info(
            "Campaign suspended. [id=" + campaign.getId() + ", name=" + campaign.getName() + "]");
        suspendCampaignIds.add(campaign.getId());
      } else if (BudgetUtils.isBudgetWarning(campBudget)) {
        // 预算预警
        log.info(
            "Campaign budget warning. [id="
                + campaign.getId()
                + ", name="
                + campaign.getName()
                + "]");
        warningCampaignIds.add(campaign.getId());
      }

      // 更新广告主的最新余额,即余额减去当前时间段广告主所有活动的开销
      // TODO: 要准确的计算广告主余额,最好要把CPM、CPC等一起计算才准确。
      updateAdvertiserCurrentBalance(advertiserBalances, comm, campaign.getAdvertiserId());
    }

    // 将余额不足的广告主的活动加入Suspend列表
    log.info("Number of advertiser: " + advertiserBalances.size());
    for (Map.Entry<Integer, Long> entry : advertiserBalances.entrySet()) {
      int advertiserId = entry.getKey();
      long balance = entry.getValue();
      if (balance < 0) {
        // 余额不足
        List<Integer> campIds = adCampaignService.listCampaignIdsByAdvertiserId(advertiserId);
        log.info(
            "Advertiser out of balance. [id="
                + advertiserId
                + ", numberOfCampaigns="
                + campIds.size()
                + "]");
        suspendCampaignIds.addAll(campIds);
      } else if (BudgetUtils.isBalanceWarning(balance)) {
        // 余额预警
        List<Integer> campIds = adCampaignService.listCampaignIdsByAdvertiserId(advertiserId);
        log.info(
            "Advertiser balance warning. [id="
                + advertiserId
                + ", numberOfCampaigns="
                + campIds.size()
                + "]");
        warningCampaignIds.addAll(campIds);
      }
    }

    // 更新广告状态为Suspended,并且发送消息到广告引擎
    for (int campId : suspendCampaignIds) {
      adCampaignService.updateAdCampaignStatus(campId, AdStatusEnum.SUSPENDED);
    }
    // 发送预算预警消息给广告引擎
    eventServices.sendCampaignBudgetWarnEvent(new ArrayList<Integer>(warningCampaignIds));
    // 发送预算改变消息给广告引擎
    eventServices.sendCampaignBudgetModifyEvent(modifiedCampaignIds);

    log.info("Finish cpm stats process task.");
  }
  @Test
  @Ignore(
      "breaks in https://bamboo.hybris.com/download/HYBRISACCELERATORR-B2BACCELERATOR-BUILD, the test needs to be refactored.")
  public void shouldTriggerCreditAlertOnceForTimePeriod() throws Exception {
    /**
     * Create and order between 8000 - 10000 EUR for unit GC Sales DE Alert should be created for GC
     * Sales Rep
     */
    login("GC Sales DE Boss");

    final OrderModel order = createOrder("GC Sales DE Boss", 900, OrderStatus.CREATED);
    b2bCartService.removeSessionCart();
    Assert.assertNotNull(order);

    // Set up credit limit data for test - should not have alert sent date
    final B2BUnitModel unitLoggedIn = b2bUnitService.getUnitForUid("GC Sales DE");
    final B2BCreditLimitModel creditLimit = unitLoggedIn.getCreditLimit();
    creditLimit.setActive(Boolean.TRUE);
    creditLimit.setDateRange(B2BPeriodRange.DAY);
    creditLimit.setAmount(BigDecimal.valueOf(10000D));
    creditLimit.setAlertThreshold(BigDecimal.valueOf(8000D));
    creditLimit.setDatePeriod(null);
    creditLimit.setAlertSentDate(null);
    modelService.save(creditLimit);

    final B2BApprovalProcessModel b2bApprovalProcessModel =
        getB2BApprovalProcessModelForOrder(order);
    this.waitForProcessToEnd(b2bApprovalProcessModel.getCode(), 20000);
    this.modelService.refresh(order);
    this.modelService.refresh(b2bApprovalProcessModel);
    Assert.assertEquals(OrderStatus.APPROVED, order.getStatus());
    Assert.assertEquals(ProcessState.SUCCEEDED, b2bApprovalProcessModel.getProcessState());
    // Check Alert Sent Date exist now
    modelService.refresh(creditLimit);
    Assert.assertNotNull("AlertSendDate should have been set", creditLimit.getAlertSentDate());

    // create a second order 100 total against the same cost center which makes the orders total of
    // 9010 for the credit limit
    // the order still  exceeds Alert Limit (8000) but the total of all orders is below credit limit
    // (1000)

    final OrderModel order2 = createOrder("GC Sales DE Boss", 10, OrderStatus.CREATED);
    Assert.assertNotNull(order2);

    final B2BApprovalProcessModel b2bApprovalProcessModel2 =
        getB2BApprovalProcessModelForOrder(order2);
    this.waitForProcessToEnd(b2bApprovalProcessModel2.getCode(), 20000);
    this.modelService.refresh(order2);
    this.modelService.refresh(b2bApprovalProcessModel2);
    Assert.assertEquals(OrderStatus.APPROVED, order2.getStatus());
    Assert.assertEquals(ProcessState.SUCCEEDED, b2bApprovalProcessModel2.getProcessState());

    // Alert Sent Date was in past, so it's updated with Current Date
    modelService.refresh(creditLimit);

    Assert.assertNotNull("AlertSentDate should not be null", creditLimit.getAlertSentDate());
    Assert.assertTrue(
        String.format(
            "AlertSentDate %s shold be in the same day as %s",
            creditLimit.getAlertSentDate(), new Date()),
        DateUtils.isSameDay(creditLimit.getAlertSentDate(), new Date()));
  }
Exemplo n.º 13
0
 public static boolean isSameDay(Calendar cal1, Calendar cal2) {
   return DateUtils.isSameDay(cal1, cal2);
 }
Exemplo n.º 14
0
 @Override
 public boolean matches(Object item) {
   return DateUtils.isSameDay(date, (Date) item);
 }
Exemplo n.º 15
0
  private Sun getSunInfo(Calendar calendar, double latitude, double longitude, boolean onlyAstro) {
    double lw = -longitude * DEG2RAD;
    double phi = latitude * DEG2RAD;
    double j = DateTimeUtils.midnightDateToJulianDate(calendar) + 0.5;
    double n = getJulianCycle(j, lw);
    double js = getApproxSolarTransit(0, lw, n);
    double m = getSolarMeanAnomaly(js);
    double c = getEquationOfCenter(m);
    double lsun = getEclipticLongitude(m, c);
    double d = getSunDeclination(lsun);
    double jtransit = getSolarTransit(js, m, lsun);
    double w0 = getHourAngle(H0, phi, d);
    double w1 = getHourAngle(H0 + SUN_DIAMETER, phi, d);
    double jset = getSunsetJulianDate(w0, m, lsun, lw, n);
    double jsetstart = getSunsetJulianDate(w1, m, lsun, lw, n);
    double jrise = getSunriseJulianDate(jtransit, jset);
    double jriseend = getSunriseJulianDate(jtransit, jsetstart);
    double w2 = getHourAngle(H1, phi, d);
    double jnau = getSunsetJulianDate(w2, m, lsun, lw, n);
    double Jciv2 = getSunriseJulianDate(jtransit, jnau);

    double w3 = getHourAngle(H2, phi, d);
    double w4 = getHourAngle(H3, phi, d);
    double jastro = getSunsetJulianDate(w3, m, lsun, lw, n);
    double jdark = getSunsetJulianDate(w4, m, lsun, lw, n);
    double jnau2 = getSunriseJulianDate(jtransit, jastro);
    double jastro2 = getSunriseJulianDate(jtransit, jdark);

    Sun sun = new Sun();
    sun.setAstroDawn(new Range(DateTimeUtils.toCalendar(jastro2), DateTimeUtils.toCalendar(jnau2)));
    sun.setAstroDusk(new Range(DateTimeUtils.toCalendar(jastro), DateTimeUtils.toCalendar(jdark)));

    if (onlyAstro) {
      return sun;
    }

    sun.setNoon(
        new Range(
            DateTimeUtils.toCalendar(jtransit),
            DateTimeUtils.toCalendar(jtransit + JD_ONE_MINUTE_FRACTION)));
    sun.setRise(new Range(DateTimeUtils.toCalendar(jrise), DateTimeUtils.toCalendar(jriseend)));
    sun.setSet(new Range(DateTimeUtils.toCalendar(jsetstart), DateTimeUtils.toCalendar(jset)));

    sun.setCivilDawn(new Range(DateTimeUtils.toCalendar(Jciv2), DateTimeUtils.toCalendar(jrise)));
    sun.setCivilDusk(new Range(DateTimeUtils.toCalendar(jset), DateTimeUtils.toCalendar(jnau)));

    sun.setNauticDawn(new Range(DateTimeUtils.toCalendar(jnau2), DateTimeUtils.toCalendar(Jciv2)));
    sun.setNauticDusk(new Range(DateTimeUtils.toCalendar(jnau), DateTimeUtils.toCalendar(jastro)));

    boolean isSunUpAllDay = isSunUpAllDay(calendar, latitude, longitude);

    // daylight
    Range daylightRange = new Range();
    if (sun.getRise().getStart() == null && sun.getRise().getEnd() == null) {
      if (isSunUpAllDay) {
        daylightRange =
            new Range(
                DateTimeUtils.truncateToMidnight(calendar),
                DateTimeUtils.truncateToMidnight(addDays(calendar, 1)));
      }
    } else {
      daylightRange = new Range(sun.getRise().getEnd(), sun.getSet().getStart());
    }
    sun.setDaylight(daylightRange);

    // morning night
    Sun sunYesterday = getSunInfo(addDays(calendar, -1), latitude, longitude, true);
    Range morningNightRange = null;
    if (sunYesterday.getAstroDusk().getEnd() != null
        && DateUtils.isSameDay(sunYesterday.getAstroDusk().getEnd(), calendar)) {
      morningNightRange =
          new Range(sunYesterday.getAstroDusk().getEnd(), sun.getAstroDawn().getStart());
    } else if (isSunUpAllDay) {
      morningNightRange = new Range();
    } else {
      morningNightRange =
          new Range(DateTimeUtils.truncateToMidnight(calendar), sun.getAstroDawn().getStart());
    }
    sun.setMorningNight(morningNightRange);

    // evening night
    Range eveningNightRange = null;
    if (sun.getAstroDusk().getEnd() != null
        && DateUtils.isSameDay(sun.getAstroDusk().getEnd(), calendar)) {
      eveningNightRange =
          new Range(
              sun.getAstroDusk().getEnd(), DateTimeUtils.truncateToMidnight(addDays(calendar, 1)));
    } else {
      eveningNightRange = new Range();
    }
    sun.setEveningNight(eveningNightRange);

    // night
    if (isSunUpAllDay) {
      sun.setNight(new Range());
    } else {
      Sun sunTomorrow = getSunInfo(addDays(calendar, 1), latitude, longitude, true);
      sun.setNight(new Range(sun.getAstroDusk().getEnd(), sunTomorrow.getAstroDawn().getStart()));
    }

    // eclipse
    SunEclipse eclipse = sun.getEclipse();
    MoonCalc mc = new MoonCalc();

    double partial =
        mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_PARTIAL);
    eclipse.setPartial(DateTimeUtils.toCalendar(partial));
    double ring = mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_RING);
    eclipse.setRing(DateTimeUtils.toCalendar(ring));
    double total =
        mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_TOTAL);
    eclipse.setTotal(DateTimeUtils.toCalendar(total));

    return sun;
  }