public Map<String, Collection<Double>> targetVsAchieved() {
    final DateTime currentDate = new DateTime();
    final List<Object[]> targets = getQuery("revenue.ptis.target").list();
    final List<Object[]> finyear = getCurrentFinYear().list();
    final DateTime finYearStartDate = new DateTime(finyear.get(0)[0]);
    final DateTime finYearEndDate = new DateTime(finyear.get(0)[1]);
    final DateTime lastFinYearStartDate = finYearStartDate.minusMonths(12);
    final DateTime lastFinYearEndDate = finYearEndDate.minusMonths(12);
    final Map<String, Double> currentTarget =
        constructDatePlaceHolderForDouble(finYearStartDate, finYearEndDate, "MM-yyyy");
    final Map<String, Double> cumilativeTarget =
        constructDatePlaceHolderForDouble(finYearStartDate, finYearEndDate, "MM-yyyy");
    for (final Object[] target : targets) {
      currentTarget.put(String.valueOf(target[0]), Double.valueOf(String.valueOf(target[1])));
      cumilativeTarget.put(String.valueOf(target[0]), Double.valueOf(String.valueOf(target[2])));
    }
    final Map<String, Double> currentAcheived =
        constructDatePlaceHolderForDouble(finYearStartDate, currentDate, "MM-yyyy");
    final Map<String, Double> cumilativeAcheived =
        constructDatePlaceHolderForDouble(finYearStartDate, currentDate, "MM-yyyy");
    final List<Object[]> achieved = getQuery("revenue.ptis.achieved").list();
    for (final Object[] achieve : achieved) {
      currentAcheived.put(String.valueOf(achieve[0]), Double.valueOf(String.valueOf(achieve[1])));
      cumilativeAcheived.put(
          String.valueOf(achieve[0]), Double.valueOf(String.valueOf(achieve[2])));
    }
    final Map<String, Double> lastAcheived =
        constructDatePlaceHolderForDouble(lastFinYearStartDate, lastFinYearEndDate, "MM-yyyy");
    final Map<String, Double> lastcumilativeAcheived =
        constructDatePlaceHolderForDouble(lastFinYearStartDate, lastFinYearEndDate, "MM-yyyy");
    final Query qry = getQuery("revenue.ptis.last.achieved");
    qry.setParameter("finStartDate", startOfGivenDate(lastFinYearStartDate).toDate());
    qry.setParameter("finEndDate", startOfGivenDate(lastFinYearEndDate).toDate());
    final List<Object[]> lastAchieved = qry.list();
    for (final Object[] lastachieved : lastAchieved) {
      lastAcheived.put(
          String.valueOf(lastachieved[0]), Double.valueOf(String.valueOf(lastachieved[1])));
      lastcumilativeAcheived.put(
          String.valueOf(lastachieved[0]), Double.valueOf(String.valueOf(lastachieved[2])));
    }

    final Map<String, Collection<Double>> targetVsAchieved =
        new HashMap<String, Collection<Double>>();
    targetVsAchieved.put("target", currentTarget.values());
    targetVsAchieved.put("achieved", currentAcheived.values());
    targetVsAchieved.put("lastAcheived", lastAcheived.values());
    targetVsAchieved.put("cumilativetarget", cumilativeTarget.values());
    targetVsAchieved.put("cumilativeachieved", cumilativeAcheived.values());
    targetVsAchieved.put("lastcumilativeachieved", lastcumilativeAcheived.values());
    return targetVsAchieved;
  }
  @Test
  public void shouldGetAllPeriodsBeforeDate() throws Exception {
    DateTime currentDate = DateTime.parse("2013-01-01");
    ProcessingPeriod period1 =
        make(
            a(
                defaultProcessingPeriod,
                with(ProcessingPeriodBuilder.startDate, currentDate.toDate()),
                with(ProcessingPeriodBuilder.endDate, currentDate.plusMonths(1).toDate()),
                with(scheduleId, schedule.getId()),
                with(name, "Month1")));
    ProcessingPeriod period2 =
        make(
            a(
                defaultProcessingPeriod,
                with(ProcessingPeriodBuilder.startDate, currentDate.minusMonths(2).toDate()),
                with(ProcessingPeriodBuilder.endDate, currentDate.minusMonths(1).toDate()),
                with(scheduleId, schedule.getId()),
                with(name, "Month2")));
    ProcessingPeriod period3 =
        make(
            a(
                defaultProcessingPeriod,
                with(ProcessingPeriodBuilder.startDate, currentDate.minusMonths(1).toDate()),
                with(ProcessingPeriodBuilder.endDate, currentDate.plusMonths(1).toDate()),
                with(scheduleId, schedule.getId()),
                with(name, "Month3")));
    ProcessingPeriod period4 =
        make(
            a(
                defaultProcessingPeriod,
                with(ProcessingPeriodBuilder.startDate, currentDate.plusMonths(1).toDate()),
                with(ProcessingPeriodBuilder.endDate, currentDate.plusMonths(2).toDate()),
                with(scheduleId, schedule.getId()),
                with(name, "Month5")));

    mapper.insert(period1);
    mapper.insert(period2);
    mapper.insert(period3);
    mapper.insert(period4);
    DateTime searchStartDate = currentDate;
    List<ProcessingPeriod> searchResults =
        mapper.getAllPeriodsBefore(schedule.getId(), searchStartDate.toDate());
    for (ProcessingPeriod period : searchResults) {
      period.setModifiedDate(null);
    }
    assertThat(searchResults, is(asList(period1, period3, period2)));
  }
  public static void main(String[] args) {
    DateTime a = new DateTime();
    DateTime b = a.minusMonths(8);

    System.out.println(Months.monthsBetween(a, b).getMonths());
    System.out.println(Months.monthsBetween(b, a).getMonths());
  }
Exemplo n.º 4
0
  @Test
  public void niceTimeDeltaCanBeOutputInAlterativeLangauges() throws Exception {
    final DateTime now = DateTime.now().minusSeconds(1);

    DateTime lessThanOneMinuteAgo = now.minusSeconds(30);
    assertEquals("En este momento", spanishDateFormatter.timeSince(lessThanOneMinuteAgo.toDate()));

    DateTime oneMinuteAgo = now.minusSeconds(70);
    assertEquals("Hace 1 minuto", spanishDateFormatter.timeSince(oneMinuteAgo.toDate()));

    DateTime fiveMinutesBefore = now.minusMinutes(5);
    assertEquals("Hace 5 minutos", spanishDateFormatter.timeSince(fiveMinutesBefore.toDate()));

    DateTime anHourAgo = now.minusHours(1);
    assertEquals("Hace 1 hora", spanishDateFormatter.timeSince(anHourAgo.toDate()));

    DateTime twoHoursAgo = now.minusHours(2);
    assertEquals("Hace 2 horas", spanishDateFormatter.timeSince(twoHoursAgo.toDate()));

    DateTime oneDayAgo = now.minusDays(1);
    assertEquals("Hace 1 día", spanishDateFormatter.timeSince(oneDayAgo.toDate()));

    DateTime oneWeekAgo = now.minusWeeks(1).minusHours(1);
    assertEquals("Hace 1 semana", spanishDateFormatter.timeSince(oneWeekAgo.toDate()));

    DateTime nineMonthsAgo = now.minusMonths(9).minusWeeks(1);
    assertEquals("Hace 9 meses", spanishDateFormatter.timeSince(nineMonthsAgo.toDate()));
  }
Exemplo n.º 5
0
  @Test
  public void shouldBeAbleToOutputNiceTimeDeltas() throws Exception {
    final DateTime now = DateTime.now().minusSeconds(1);

    DateTime lessThanOneMinuteAgo = now.minusSeconds(30);
    assertEquals("just now", dateFormatter.timeSince(lessThanOneMinuteAgo.toDate()));

    DateTime fiveMinutesBefore = now.minusMinutes(5);
    assertEquals("5 minutes ago", dateFormatter.timeSince(fiveMinutesBefore.toDate()));

    DateTime anHourAgo = now.minusHours(1);
    assertEquals("1 hour ago", dateFormatter.timeSince(anHourAgo.toDate()));

    DateTime twoHoursAgo = now.minusHours(2);
    assertEquals("2 hours ago", dateFormatter.timeSince(twoHoursAgo.toDate()));

    DateTime oneDayAgo = now.minusDays(1);
    assertEquals("1 day ago", dateFormatter.timeSince(oneDayAgo.toDate()));

    DateTime oneWeekAgo = now.minusWeeks(1).minusHours(1);
    assertEquals("1 week ago", dateFormatter.timeSince(oneWeekAgo.toDate()));

    DateTime nineMonthsAgo = now.minusMonths(9).minusWeeks(1);
    assertEquals("9 months ago", dateFormatter.timeSince(nineMonthsAgo.toDate()));
  }
Exemplo n.º 6
0
 /** @return a Project object populated with test values. */
 public static Project project() {
   DateTime currentDate = new DateTime();
   Project project = new Project();
   project.setName("project name");
   project.setStartDate(currentDate.minusMonths(6).toDate());
   project.setEndDate(currentDate.plusMonths(6).toDate());
   return project;
 }
Exemplo n.º 7
0
  protected void addDateFilter(Form<Object> form) {
    DateTime currentDateTime = new DateTime(new Date());
    toDateM = new Model<Date>(currentDateTime.toDate());
    fromDateM = new Model<Date>(currentDateTime.minusMonths(1).toDate());

    form.add(new DateTextField("from", fromDateM));
    form.add(new DateTextField("to", toDateM));
  }
Exemplo n.º 8
0
 public static Date getDateFromDateDesc(String leadTime) {
   DateTime dateTime = new DateTime(0, 12, 31, 0, 0, 0, 0);
   if (!Strings.isEmpty(leadTime)) {
     String time = "0";
     if (leadTime.indexOf(".") > 0) {
       time = leadTime.substring(0, leadTime.indexOf("."));
     } else {
       time = leadTime.substring(0, leadTime.length() - 1);
     }
     int timeVal = Integer.parseInt(time);
     if (leadTime.indexOf(DAY) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusDays(timeVal);
       } else {
         dateTime = dateTime.minusDays(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(WEEK) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusWeeks(timeVal);
       } else {
         dateTime = dateTime.minusWeeks(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(MONTH) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal));
       }
     } else if (leadTime.indexOf(QUARTER) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusMonths(timeVal * 3);
       } else {
         dateTime = dateTime.minusMonths(Math.abs(timeVal * 3));
       }
     } else if (leadTime.indexOf(YEAR) >= 0) {
       if (timeVal > 0) {
         dateTime = dateTime.plusYears(timeVal);
       } else {
         dateTime = dateTime.minusYears(Math.abs(timeVal));
       }
     }
     return dateTime.toDate();
   }
   return dateTime.toDate();
 }
  @Test
  public void shouldGetAllPeriodsAfterAGivenDate() throws Exception {
    DateTime date1 = new DateTime();
    DateTime date2 = date1.minusMonths(1);
    DateTime date3 = date1.minusMonths(2);
    DateTime date4 = date1.minusMonths(3);
    DateTime date5 = date1.minusMonths(4);
    DateTime futureDate = date1.plusMonths(1);

    insertProcessingPeriod("Period 1", date5, date4);
    ProcessingPeriod period2 = insertProcessingPeriod("Period 2", date4.plusDays(1), date3);
    ProcessingPeriod period3 = insertProcessingPeriod("Period 3", date3.plusDays(1), date2);
    ProcessingPeriod period4 = insertProcessingPeriod("Period 4", date2.plusDays(1), date1);
    insertProcessingPeriod("Period 5", date1.plusDays(1), futureDate);

    List<ProcessingPeriod> relevantPeriods =
        mapper.getAllPeriodsAfterDate(schedule.getId(), date3.toDate(), date1.toDate());

    assertThat(relevantPeriods.size(), is(3));
    assertThat(relevantPeriods.get(0).getId(), is(period2.getId()));
    assertThat(relevantPeriods.get(1).getId(), is(period3.getId()));
    assertThat(relevantPeriods.get(2).getId(), is(period4.getId()));
  }
Exemplo n.º 10
0
  // TOOLS
  private DateTime getDateLimit(final boolean upper) {
    final Date date = DateUtils.truncate(new Date(), Calendar.DATE);
    final DateTime now = new DateTime(date);

    switch (type) {
      case YEAR:
        return upper ? now.plusYears(upperBoundary) : now.minusYears(lowerBoundary);
      case MONTH:
        return upper ? now.plusMonths(upperBoundary) : now.minusMonths(lowerBoundary);
      case DAY:
        return upper ? now.plusDays(upperBoundary) : now.minusDays(lowerBoundary);
      default:
        throw new IllegalArgumentException("Unsupported type of time unit: " + type);
    }
  }
Exemplo n.º 11
0
 @Override
 public CashFlowBoundary getCashFlowBoundary(
     DateTime firstInstallmentDueDate, DateTime lastInstallmentDueDate) {
   DateTime monthAfterLastInstallment =
       lastInstallmentDueDate
           .plusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE)
           .withDayOfMonth(FIRST_DAY);
   DateTime monthBeforeFirstInstallment =
       firstInstallmentDueDate
           .minusMonths(EXTRA_DURATION_FOR_CASH_FLOW_SCHEDULE)
           .withDayOfMonth(FIRST_DAY);
   int numberOfMonths =
       Months.monthsBetween(monthBeforeFirstInstallment, monthAfterLastInstallment).getMonths()
           + 1;
   return new CashFlowBoundary(
       monthBeforeFirstInstallment.getMonthOfYear(),
       monthBeforeFirstInstallment.getYear(),
       numberOfMonths);
 }
Exemplo n.º 12
0
 public SaldoStok cari(Produk p, Date tanggal, Cabang cabang) {
   DateTime dateTime = new DateTime();
   String bulan = StringUtils.bulanDuaDigit(dateTime.toDate());
   String tahun = String.valueOf(dateTime.getYear());
   SaldoStok s = cari(p, tahun, bulan);
   if (s == null) {
     // cari satu bulan sebelumnya
     bulan = StringUtils.bulanDuaDigit(dateTime.minusMonths(1).toDate());
     SaldoStok bulanSebelumnya = cari(p, tahun, bulan);
     if (bulanSebelumnya == null) {
       List<SaldoStok> saldoStoks =
           sessionFactory
               .getCurrentSession()
               .createQuery(
                   "from SaldoStok s "
                       + "where s.produk.id=:id "
                       + "order by s.tahun desc, s.bulan desc")
               .setString("id", p.getId())
               .list();
       if (!saldoStoks.isEmpty()) {
         bulanSebelumnya = saldoStoks.get(0);
       }
     }
     s = new SaldoStok();
     s.setId(
         runningNumberDao.ambilBerikutnyaDanSimpan(
             TransaksiRunningNumberEnum.SALDO_STOK, tanggal, cabang.getId()));
     s.setProduk(p);
     if (bulanSebelumnya != null) {
       s.setSaldoAwal(
           bulanSebelumnya.getBeli()
               + bulanSebelumnya.getReturJual()
               - bulanSebelumnya.getJual()
               - bulanSebelumnya.getReturBeli()
               + bulanSebelumnya.getSaldoAwal());
     }
     simpan(s);
   }
   return s;
 }
Exemplo n.º 13
0
  /**
   * 计算指定时间之前的日期
   *
   * @param date 待计算时间
   * @param random 待计算数
   * @param timeType 时间类型枚举
   * @see org.codingsills.modules.utils.DateKit.TimeType
   * @return Date
   */
  public static Date preDate(Date date, int random, TimeType timeType) {
    Date preDate = null;
    if (date == null) {
      return preDate;
    }
    DateTime dateTime = fromDate(date);
    random = Math.abs(random);
    switch (timeType.getCode()) {
      case "Y":
        preDate = dateTime.minusYears(random).toDate();
        break;
      case "M":
        preDate = dateTime.minusMonths(random).toDate();
        break;
      case "W":
        preDate = dateTime.minusWeeks(random).toDate();
        break;
      case "D":
        preDate = dateTime.minusDays(random).toDate();
        break;
      case "H":
        preDate = dateTime.minusHours(random).toDate();
        break;
      case "MIN":
        preDate = dateTime.minusMinutes(random).toDate();
        break;
      case "S":
        preDate = dateTime.minusSeconds(random).toDate();
        break;
      case "MS":
        preDate = dateTime.minusMillis(random).toDate();
        break;
      default:
        break;
    }

    return preDate;
  }
Exemplo n.º 14
0
 public static Date minusMonths(Date date, int numberOfmonths) {
   if (date == null) date = new Date();
   DateTime dt = new DateTime(date);
   return dt.minusMonths(numberOfmonths).toDate();
 }
  private Patient createPatient() {
    Person person = new Person();

    // Add address
    PersonAddress address = new PersonAddress();
    address.setAddress1(ViewUtils.getInput(edaddr1));
    address.setAddress2(ViewUtils.getInput(edaddr2));
    address.setCityVillage(ViewUtils.getInput(edcity));
    address.setPostalCode(ViewUtils.getInput(edpostal));
    address.setCountry(ViewUtils.getInput(edcountry));
    address.setStateProvince(ViewUtils.getInput(edstate));
    address.setPreferred(true);

    List<PersonAddress> addresses = new ArrayList<>();
    addresses.add(address);
    person.setAddresses(addresses);

    // Add names
    PersonName name = new PersonName();
    name.setFamilyName(ViewUtils.getInput(edlname));
    name.setGivenName(ViewUtils.getInput(edfname));
    name.setMiddleName(ViewUtils.getInput(edmname));

    List<PersonName> names = new ArrayList<>();
    names.add(name);
    person.setNames(names);

    // Add gender
    String[] genderChoices = {"M", "F"};
    int index = gen.indexOfChild(getActivity().findViewById(gen.getCheckedRadioButtonId()));
    if (index != -1) {
      person.setGender(genderChoices[index]);
    } else {
      person.setGender(null);
    }

    // Add birthdate
    String birthdate = null;
    if (ViewUtils.isEmpty(eddob)) {
      if (!StringUtils.isBlank(ViewUtils.getInput(edyr))
          || !StringUtils.isBlank(ViewUtils.getInput(edmonth))) {
        int yeardiff = ViewUtils.isEmpty(edyr) ? 0 : Integer.parseInt(edyr.getText().toString());
        int mondiff =
            ViewUtils.isEmpty(edmonth) ? 0 : Integer.parseInt(edmonth.getText().toString());
        LocalDate now = new LocalDate();
        bdt = now.toDateTimeAtStartOfDay().toDateTime();
        bdt = bdt.minusYears(yeardiff);
        bdt = bdt.minusMonths(mondiff);
        person.setBirthdateEstimated(true);
        birthdate = bdt.toString();
      }
    } else {
      birthdate = bdt.toString();
    }

    person.setBirthdate(birthdate);

    final Patient patient = new Patient();
    patient.setPerson(person);
    patient.setUuid(" ");
    return patient;
  }
Exemplo n.º 16
0
 @PostConstruct
 public void postConstruct() {
   DateTime dt = new DateTime();
   this.startdate = dt.minusMonths(1).dayOfMonth().withMaximumValue().toString("yyyyMMdd");
 }