Example usage for org.joda.time DateTime getYear

List of usage examples for org.joda.time DateTime getYear

Introduction

In this page you can find the example usage for org.joda.time DateTime getYear.

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:com.hmsinc.epicenter.webapp.chart.TimeSeriesChart.java

License:Open Source License

/**
 * @param period//from  w  ww  .ja  v  a  2  s.co m
 * @param date
 * @return
 */
private static org.jfree.data.time.RegularTimePeriod getEntryPeriod(final TimeSeriesPeriod period,
        final DateTime date) {

    final org.jfree.data.time.RegularTimePeriod ret;

    switch (period) {
    case DAY:
        ret = new Day(date.getDayOfMonth(), date.getMonthOfYear(), date.getYear());
        break;
    case HOUR:
        ret = new Hour(date.getHourOfDay(), date.getDayOfYear(), date.getMonthOfYear(), date.getYear());
        break;
    case MONTH:
        ret = new Month(date.getMonthOfYear(), date.getYear());
        break;
    case YEAR:
        ret = new Year(date.getYear());
        break;
    default:
        throw new UnsupportedOperationException("Unsupported period: " + period);
    }

    return ret;

}

From source file:com.hmsinc.epicenter.webapp.remoting.ForecastingService.java

License:Open Source License

@Secured("ROLE_USER")
@Transactional(readOnly = true)//from  w w w.  j a va  2s. c  om
@RemoteMethod
public String getSeasonalTrendChart(final AnalysisParametersDTO paramsDTO) {

    final AnalysisParameters params = convertParameters(paramsDTO);

    // 60 day window
    final DateTime windowStart = params.getEndDate().minusDays(59);

    // Set the start date back 1 year + 60 days
    params.setStartDate(windowStart.minusYears(1).minusDays(59));

    final TimeSeriesChart chart = new TimeSeriesChart();

    final TimeSeries ts = queryService.queryForTimeSeries(params, paramsDTO.getAlgorithmName(), null);

    if (ts != null) {

        final TimeSeries forecast = waveletSeasonalTrendForecaster.process(ts.after(windowStart),
                ts.before(windowStart.minusDays(1)), null);
        final TimeSeries known = forecast.before(params.getEndDate());
        final TimeSeries predicted = forecast.after(params.getEndDate().plusDays(1));

        chart.addBand("70% Confidence Prediction", predicted, ResultType.LOWER_BOUND_70,
                ResultType.UPPER_BOUND_70, new Color(0x0072bf), new Color(0x0072bf));
        chart.addBand("80% Confidence Prediction", predicted, ResultType.LOWER_BOUND_80,
                ResultType.UPPER_BOUND_80, new Color(0x0099ff), new Color(0x0099ff));
        chart.addBand("90% Confidence Prediction", predicted, ResultType.LOWER_BOUND_90,
                ResultType.UPPER_BOUND_90, new Color(0x3fb2ff), new Color(0x3fb2ff));
        chart.addBand("95% Confidence Prediction", predicted, ResultType.LOWER_BOUND_95,
                ResultType.UPPER_BOUND_95, new Color(0xbfe5ff), new Color(0xbfe5ff));

        chart.add("Actual Value", known, ChartColor.VALUE.getColor(), LineStyle.DOTTED);
        chart.add("Actual Trend", known, ResultType.TREND, ChartColor.VALUE.getColor(), LineStyle.THICK);

        final DateTime knownFirst = known.first().getTime();
        final DateTime predictedFirst = predicted.first().getTime();

        final Marker marker = new IntervalMarker(
                new Day(knownFirst.getDayOfMonth(), knownFirst.getMonthOfYear(), knownFirst.getYear())
                        .getFirstMillisecond(),
                new Day(predictedFirst.getDayOfMonth(), predictedFirst.getMonthOfYear(),
                        predictedFirst.getYear()).getFirstMillisecond(),
                Color.LIGHT_GRAY, new BasicStroke(2.0f), null, null, 1.0f);
        marker.setAlpha(0.3f);
        chart.getMarkers().add(marker);
        chart.setYLabel(params.getDataRepresentation().getDisplayName());
        chart.setAlwaysScaleFromZero(false);
    }

    return chartService.getChartURL(chart);

}

From source file:com.huang.rp.common.utils.TimeUtils.java

License:Apache License

/**
 * ?/*from   ww w. j a va  2 s . c  o m*/
 * @return
 */
public static String getYYMMDDStr() {
    DateTime dt = new DateTime();
    StringBuilder sb = new StringBuilder();
    sb.append(dt.getYear()).append(dt.getMonthOfYear()).append(dt.getDayOfMonth());
    return sb.toString();
}

From source file:com.hurence.logisland.util.time.DateUtil.java

License:Apache License

/**
 * Validate the actual date of the given date string based on the given date format pattern and
 * return a date instance based on the given date string.
 * @param dateString The date string.//from  ww w . ja  v  a2s . c o  m
 * @param dateFormat The date format pattern which should respect the SimpleDateFormat rules.
 * @param timeZone The timezone to use to parse the date.
 * @return The parsed date object.
 * @throws ParseException If the given date string or its actual date is invalid based on the
 * given date format pattern.
 * @see SimpleDateFormat
 */
public static Date parse(String dateString, String dateFormat, TimeZone timeZone) throws ParseException {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, new Locale("en", "US"));
    simpleDateFormat.setTimeZone(timeZone);
    simpleDateFormat.setLenient(false); // Don't automatically convert invalid date.
    if (dateFormat.equals("MMM dd HH:mm:ss")) {

        DateTime today = new DateTime();
        DateTime parsedDate = new DateTime(simpleDateFormat.parse(dateString));

        DateTime parsedDateWithTodaysYear = parsedDate.withYear(today.getYear());

        return parsedDateWithTodaysYear.toDate();
    } else {
        return simpleDateFormat.parse(dateString);
    }
}

From source file:com.inkubator.hrm.service.impl.ScheduleServiceImpl.java

@Scheduled(cron = "${cron.update.wt.holiday.date.where.is.every.year.equal.one}")
@Transactional(readOnly = false, isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Override/*w  ww.  j av  a  2  s.c o m*/
public void updateWtHolidayDateWhereIsEveryYearIsOne() throws Exception {
    LOGGER.info("Begin Running Update WtHoliday");
    //ambil bulan dan taun januari sekarang
    DateTime monthAndYearNow = new DateTime();
    List<WtHoliday> dataToUpdate = wtHolidayDao.getByYearDif(difWeekToDelete);
    LOGGER.info("Ukuran Data to Update " + dataToUpdate.size());
    Date date = new Date();
    WtHoliday newData;
    Long totalDuplicat;
    for (WtHoliday wtHoliday : dataToUpdate) {
        //ambil bulan dan tahun yang akan di update
        DateTime monthAndYearBefore = new DateTime(wtHoliday.getHolidayDate());
        //jika tahun di database lebih kecil tahun sekarang
        if (monthAndYearBefore.getYear() < monthAndYearNow.getYear()
                && monthAndYearBefore.getMonthOfYear() >= monthAndYearNow.getMonthOfYear()) {
            //           
            //cari nama + tahun, jika sudah ada skip, karena unik
            totalDuplicat = wtHolidayDao.getTotalWtHolidayByHolidayName(
                    wtHoliday.getHolidayName() + " " + monthAndYearNow.getYear());
            if (totalDuplicat == 0) {
                Date updateHolidayDate = DateTimeUtil.getDateFrom(wtHoliday.getHolidayDate(), 1,
                        CommonUtilConstant.DATE_FORMAT_YEAR);
                newData = new WtHoliday();
                newData.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(9)));
                newData.setHolidayName(wtHoliday.getHolidayName() + " " + monthAndYearNow.getYear());
                newData.setIsColectiveLeave(wtHoliday.getIsColectiveLeave());
                newData.setIsEveryYear(wtHoliday.getIsEveryYear());
                if (wtHoliday.getReligion() != null) {
                    newData.setReligion(wtHoliday.getReligion());
                }
                newData.setCreatedBy(HRMConstant.INKUBA_SYSTEM);
                newData.setCreatedOn(new Date());
                newData.setHolidayDate(updateHolidayDate);
                wtHolidayDao.save(newData);
            }
        }
    }
    LOGGER.info("Finish Running Update Wt Holiday");
}

From source file:com.inkubator.hrm.service.impl.WtHolidayCronListenerServiceImpl.java

public void updateWtHolidayDateWhereIsEveryYearIsOne() throws Exception {

    LOGGER.warn("Begin Running Update WtHoliday");
    //ambil bulan dan taun januari sekarang
    DateTime monthAndYearNow = new DateTime();
    List<WtHoliday> dataToUpdate = wtHolidayDao.getByYearDif(difWeekToDelete);
    LOGGER.info("Ukuran Data to Update " + dataToUpdate.size());
    Date date = new Date();
    WtHoliday newData;/*from  ww  w.  j ava2  s  . c om*/
    Long totalDuplicat;
    for (WtHoliday wtHoliday : dataToUpdate) {
        //ambil bulan dan tahun yang akan di update
        DateTime monthAndYearBefore = new DateTime(wtHoliday.getHolidayDate());
        //jika tahun di database lebih kecil tahun sekarang
        if (monthAndYearBefore.getYear() < monthAndYearNow.getYear()
                && monthAndYearBefore.getMonthOfYear() >= monthAndYearNow.getMonthOfYear()) {
            //           
            //cari nama + tahun, jika sudah ada skip, karena unik
            totalDuplicat = wtHolidayDao.getTotalWtHolidayByHolidayName(
                    wtHoliday.getHolidayName() + " " + monthAndYearNow.getYear());
            if (totalDuplicat == 0) {
                Date updateHolidayDate = DateTimeUtil.getDateFrom(wtHoliday.getHolidayDate(), 1,
                        CommonUtilConstant.DATE_FORMAT_YEAR);
                newData = new WtHoliday();
                newData.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(9)));
                newData.setHolidayName(wtHoliday.getHolidayName() + " " + monthAndYearNow.getYear());
                newData.setIsColectiveLeave(wtHoliday.getIsColectiveLeave());
                newData.setIsEveryYear(wtHoliday.getIsEveryYear());
                if (wtHoliday.getReligion() != null) {
                    newData.setReligion(wtHoliday.getReligion());
                }
                newData.setCreatedBy(HRMConstant.INKUBA_SYSTEM);
                newData.setCreatedOn(new Date());
                newData.setHolidayDate(updateHolidayDate);
                wtHolidayDao.save(newData);
            }
        }
    }
    LOGGER.info("Finish Running Update Wt Holiday");
}

From source file:com.inkubator.hrm.util.KodefikasiUtil.java

public static String getKodefikasi(int maxNumerData, String pattern) {
    String afterString = StringUtils.substringAfter(pattern, "[");
    String beforeString = StringUtils.substringBefore(pattern, "[");
    String removeParenties1 = StringUtils.remove(afterString, "[");
    String removeParenties2 = StringUtils.remove(removeParenties1, "]");
    int numberOfYear = StringUtils.countMatches(removeParenties2, "Y");
    int numberofN = StringUtils.countMatches(removeParenties2, "N");

    int currentNumber = maxNumerData + 1;
    int numberofNEx = String.valueOf(currentNumber).length();

    int selisih = numberofN - numberofNEx;

    String montInString = null;//from  w ww .ja  v  a 2  s  .co  m
    String yearInString = null;
    String dayInString = null;
    String numberInString = null;
    if (selisih == 0) {
        numberInString = String.valueOf(currentNumber);
    } else {
        numberInString = StringUtils.leftPad(String.valueOf(currentNumber), numberofN, "0");
    }
    DateTime jodaTime = new DateTime();
    int year = jodaTime.getYear();
    int month = jodaTime.getMonthOfYear();
    int day = jodaTime.getDayOfMonth();

    if (month < 10) {
        montInString = "0" + month;
    } else {
        montInString = String.valueOf(month);
    }
    if (numberOfYear == 2) {
        year = Integer.parseInt(new SimpleDateFormat("YY").format(new Date()));
        if (year < 10) {
            yearInString = "0" + year;
        } else {
            yearInString = String.valueOf(year);
        }
    } else {
        yearInString = String.valueOf(year);
    }

    if (day < 10) {
        dayInString = "0" + day;
    } else {
        dayInString = String.valueOf(day);
    }
    String output1 = StringUtils.replaceOnce(removeParenties2, "Y", yearInString);
    String output2 = StringUtils.remove(output1, "Y");
    String output3 = StringUtils.replaceOnce(output2, "M", montInString);
    String output4 = StringUtils.remove(output3, "M");
    String output5 = StringUtils.replaceOnce(output4, "D", dayInString);
    String output6 = StringUtils.remove(output5, "D");
    String output7 = StringUtils.replaceOnce(output6, "N", numberInString);
    String output8 = StringUtils.remove(output7, "N");
    return beforeString + output8;

}

From source file:com.inkubator.hrm.util.KodefikasiUtil.java

public static String getKodefikasiOnlyPattern(String pattern) {
    String afterString = StringUtils.substringAfter(pattern, "[");
    String beforeString = StringUtils.substringBefore(pattern, "[");
    String removeParenties1 = StringUtils.remove(afterString, "[");
    String removeParenties2 = StringUtils.remove(removeParenties1, "]");
    int numberOfYear = StringUtils.countMatches(removeParenties2, "Y");
    int numberofN = StringUtils.countMatches(removeParenties2, "N");

    //        int currentNumber = maxNumerData + 1;
    //        int numberofNEx = String.valueOf(currentNumber).length();

    //        int selisih = numberofN - numberofNEx;

    String montInString = null;//from  www  .  j av a2  s  .c  om
    String yearInString = null;
    String dayInString = null;
    String numberInString = null;
    //        if (selisih == 0) {
    //            numberInString = String.valueOf(currentNumber);
    //        } else {
    ////            numberInString = StringsUtils.leftPad(String.valueOf(currentNumber), numberofN, "0");
    //        }
    DateTime jodaTime = new DateTime();
    int year = jodaTime.getYear();
    int month = jodaTime.getMonthOfYear();
    int day = jodaTime.getDayOfMonth();

    if (month < 10) {
        montInString = "0" + month;
    } else {
        montInString = String.valueOf(month);
    }
    if (numberOfYear == 2) {
        year = Integer.parseInt(new SimpleDateFormat("YY").format(new Date()));
        if (year < 10) {
            yearInString = "0" + year;
        } else {
            yearInString = String.valueOf(year);
        }
    } else {
        yearInString = String.valueOf(year);
    }

    if (day < 10) {
        dayInString = "0" + day;
    } else {
        dayInString = String.valueOf(day);
    }
    String output1 = StringUtils.replaceOnce(removeParenties2, "Y", yearInString);
    String output2 = StringUtils.remove(output1, "Y");
    String output3 = StringUtils.replaceOnce(output2, "M", montInString);
    String output4 = StringUtils.remove(output3, "M");
    String output5 = StringUtils.replaceOnce(output4, "D", dayInString);
    String output6 = StringUtils.remove(output5, "D");
    //        String output7 = StringsUtils.replaceOnce(output6, "N", numberInString);
    //        String output8 = StringsUtils.remove(output7, "N");
    return beforeString + output6;
}

From source file:com.inspireVeiN.iPlayed.iPlayedPlayerListener.java

License:Open Source License

private void login(Player p) {
    String player = p.getName();//from   ww  w. j  a  v  a  2  s.co m
    Arguments entry = null;
    if (plugin.timesdb.hasIndex(player))
        entry = plugin.timesdb.getArguments(player);
    else {
        entry = new Arguments(player);
        entry.setValue("playtime", "0");
        plugin.timesdb.addIndex(player, entry);
        plugin.timesdb.update();
    }
    DateTime dt = new DateTime();
    plugin.timesdb.setArgument(player, "lastlogin",
            dt.getMonthOfYear() + "/" + dt.getDayOfMonth() + "/" + dt.getYear(), true);
    plugin.timesdb.setArgument(player, "startTime", Integer.toString(dt.getMinuteOfDay()), true);
}

From source file:com.krminc.phr.web.PHRCalendar.java

License:Apache License

public PHRCalendar(Long healthRecordId) {
    this.healthRecordId = healthRecordId;
    this.healthRecord = lookupHealthRecord(this.healthRecordId);
    // TODO: Is there a way we can do this without creating an object?
    DateTime now = new DateTime();
    this.year = now.getYear();
    this.month = now.getMonthOfYear();
}