Example usage for java.util Calendar getActualMinimum

List of usage examples for java.util Calendar getActualMinimum

Introduction

In this page you can find the example usage for java.util Calendar getActualMinimum.

Prototype

public int getActualMinimum(int field) 

Source Link

Document

Returns the minimum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:com.hihframework.core.utils.DateUtils.java

/**
 * ?00:00:00.000? param:2004-08-20 return:2004-08-01
 * 00.00.00.000//from w w  w  .j  a  v  a 2 s.  co m
 *
 * @param date 
 * @return ?
 */
public static Timestamp getMinDayInMonth(java.sql.Date date) {

    Calendar cale = Calendar.getInstance();
    cale.setTime(date);
    cale.set(Calendar.DAY_OF_MONTH, cale.getActualMinimum(Calendar.DAY_OF_MONTH));
    java.sql.Date newDate = new java.sql.Date(cale.getTimeInMillis());

    cale = null;
    return Timestamp.valueOf(newDate.toString() + " 00:00:00.000");

}

From source file:de.inren.service.car.CarLogEntryServiceImpl.java

@Override
public List<CarLogEntry> loadLogEntriesForCarAndMonth(Long id, Date date) {
    // TODO use Specification
    List<CarLogEntry> result = new ArrayList<>();
    List<CarLogEntry> all = loadLogEntriesForCar(id);
    LocalDateTime jodaDate = LocalDateTime.fromDateFields(date);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from ww w  .ja  v  a2 s. c  o m
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    setTimeToBeginningOfDay(calendar);
    final Date begining = calendar.getTime();

    calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    setTimeToEndofDay(calendar);
    final Date end = calendar.getTime();

    for (CarLogEntry entry : all) {
        if (entry.getPitStopDate().after(begining) && entry.getPitStopDate().before(end)) {
            result.add(entry);
        }
    }
    return result;
}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

@Test
public void testDefaultTimeCoverageSelector() throws Exception {
    // Use default default value strategy: 
    setupCoverageTimeDimension(WATTEMP_FUTURE, null);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    long todayMidnight = cal.getTimeInMillis();

    CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart());

    java.util.Date d = wms.getDefaultTime(coverage);
    assertTrue("Returns a valid Default time", d != null);
    assertTrue("Default time should be the closest one", d.getTime() == todayMidnight);
}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

@Test
public void testExplicitCurrentTimeCoverageSelector() throws Exception {
    // Use explicit default value strategy: 
    DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting();
    defaultValueSetting.setStrategyType(Strategy.NEAREST);
    defaultValueSetting.setReferenceValue(DimensionDefaultValueSetting.TIME_CURRENT);
    setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    long todayMidnight = cal.getTimeInMillis();

    CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart());

    java.util.Date d = wms.getDefaultTime(coverage);
    assertTrue("Returns a valid Default time", d != null);
    assertTrue("Default time should be the closest one", d.getTime() == todayMidnight);
}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

@Test
public void testExplicitMaxTimeCoverageSelector() throws Exception {
    // Use explicit default value strategy: 
    DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting();
    defaultValueSetting.setStrategyType(Strategy.MAXIMUM);
    setupCoverageTimeDimension(WATTEMP_FUTURE, defaultValueSetting);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));

    cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
    long oneYearInFuture = cal.getTimeInMillis();

    CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart());

    java.util.Date d = wms.getDefaultTime(coverage);
    assertTrue("Returns a valid Default time", d != null);
    assertTrue("Default time should be the biggest one", d.getTime() == oneYearInFuture);
}

From source file:org.geoserver.wms.dimension.RasterTimeDimensionDefaultValueTest.java

private void prepareFutureCoverageData(QName coverageName) throws IOException {
    SimpleDateFormat tsFormatter = new SimpleDateFormat("yyyyMMdd");

    // Prepare the target dates for the dummy coverages to be created
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    long justPast = cal.getTimeInMillis();

    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);
    long oneMonthInFuture = cal.getTimeInMillis();

    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));

    cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
    long oneYearInFuture = cal.getTimeInMillis();

    // Copy watertemp.zip test coverage resource in the data dir under a different name:
    GeoServerResourceLoader loader = getCatalog().getResourceLoader();
    File targetDir = loader.createDirectory(getDataDirectory().root(),
            coverageName.getPrefix() + File.separator + coverageName.getLocalPart());
    File target = new File(targetDir, coverageName.getLocalPart() + ".zip");
    loader.copyFromClassPath("org/geoserver/wms/dimension/watertemp.zip", target);

    // unpack the archive
    IOUtils.decompress(target, targetDir);

    // delete archive
    target.delete();/*from  w  ww  .  j  av  a2s.  c  o m*/

    // Make three new dummy coverage files with the needed timestamps:
    File input = null;
    File output = null;
    FilenameFilter tiffFilter = new DefaultFileFilter("*.tiff");
    String[] tiffnames = targetDir.list(tiffFilter);

    if (tiffnames != null) {
        if (tiffnames.length > 0) {
            input = new File(targetDir, tiffnames[0]);
            output = new File(targetDir,
                    "DUMMY_watertemp_000_" + tsFormatter.format(new Date(justPast)) + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);

            output = new File(targetDir, "DUMMY_watertemp_000_" + tsFormatter.format(new Date(oneMonthInFuture))
                    + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);

            output = new File(targetDir, "DUMMY_watertemp_000_" + tsFormatter.format(new Date(oneYearInFuture))
                    + "T0000000_12.tiff");
            FileUtils.copyFile(input, output);
        }
    }
    addRasterLayerFromDataDir(WATTEMP_FUTURE, getCatalog());

}

From source file:me.diskstation.ammon.gpsrunner.ui.CalendarFragment.java

protected ArrayList<Run> getRuns(final Bundle args) {
    int year = args.getInt("spinner_selection_year");
    int month = args.getInt("spinner_selection_month");
    Calendar calendar = Calendar.getInstance();
    if (year != 0) {
        calendar.set(Calendar.YEAR, year);
    }//from   w w  w  .ja  v a  2  s  .co  m
    if (month != 0) {
        calendar.set(Calendar.MONTH, month);
    }
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND));
    long startTimestamp = calendar.getTimeInMillis();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));
    long endTimestamp = calendar.getTimeInMillis();
    LocationDBHelper dbHelp = new LocationDBHelper(getActivity());
    LocationDBReader dbRead = new LocationDBReader(dbHelp);
    return dbRead.getRuns(startTimestamp, endTimestamp, "ASC");
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ?/*from w w w.ja va  2 s  .c o m*/
 * 
 * @param date
 * @return
 */
public static Date getFirstDateOfMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
    return c.getTime();
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * /* w  ww .  j a v a2  s .c  o m*/
 * 
 * @param date
 * @return
 */
public static Date getFirstDayOfMonth(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
    return calendar.getTime();
}

From source file:com.gnizr.core.util.GnizrDaoUtil.java

public static Date[] getTimeRangeDate(int timeRange) {
    Date[] dates = new Date[2];
    Date now = GnizrDaoUtil.getNow();
    dates[0] = GnizrDaoUtil.toDayBegins(now);
    dates[1] = GnizrDaoUtil.toDayEnds(now);
    if (TimeRange.TODAY == timeRange) {
        return dates;
    } else if (TimeRange.YESTERDAY == timeRange) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dates[0]);// w  ww . ja v  a  2s.  c o m
        cal.add(Calendar.DAY_OF_MONTH, -1);
        dates[0] = cal.getTime();

        cal.setTime(dates[1]);
        cal.add(Calendar.DAY_OF_MONTH, -1);
        dates[1] = cal.getTime();
    } else if (TimeRange.LAST_7_DAYS == timeRange) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dates[0]);
        cal.add(Calendar.DAY_OF_MONTH, -6);
        dates[0] = cal.getTime();
    } else if (TimeRange.THIS_MONTH == timeRange) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dates[0]);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        dates[0] = cal.getTime();
    } else if (TimeRange.LAST_MONTH == timeRange) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dates[0]);
        cal.add(Calendar.MONTH, -1);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        dates[0] = cal.getTime();

        cal.setTime(dates[1]);
        cal.add(Calendar.MONTH, -1);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        dates[1] = cal.getTime();
    } else {
        return null;
    }
    return dates;
}