List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:org.richfaces.tests.page.fragments.impl.calendar.common.editor.time.RichFacesTimeEditor.java
License:Open Source License
@Override public DateTime getTime() { int seconds = (getSecondsSpinner() != null ? getSecondsSpinner().getValue() : defaultSeconds); int minutes = (getMinutesSpinner() != null ? getMinutesSpinner().getValue() : defaultMinutes); int hours = (getHoursSpinner() != null ? getHoursSpinner().getValue() : defaultHours); DateTime result = new DateTime().withHourOfDay(hours).withMinuteOfHour(minutes).withSecondOfMinute(seconds); RichFacesTimeSignSpinner tss = getTimeSignSpinner(); if (tss != null) { switch (tss.getValue()) { case AM:// w w w . java 2 s.c om if (result.getHourOfDay() == 12) {//12:xx am -> 00:xx result = result.minusHours(12); } break; case PM: if (result.getHourOfDay() != 12) { result = result.plusHours(12); } break; default: throw new IllegalArgumentException("Unknown switch"); } } return result; }
From source file:org.rockholla.date.DateUtility.java
License:Open Source License
/** * Formats a datetime for use in a MySQL datetime field * //w w w .j a va 2 s . co m * @param dateTime the org.joda.time.DateTime value to format * @param offset offset the input datetime by this amount of hours * @return the formatted datetime */ public static String getMySqlDate(DateTime dateTime, int offset) { if (offset > 0 || offset < 0) { dateTime = dateTime.plusHours(offset); } String result = String.valueOf(dateTime.getYear()) + "-" + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + "-" + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + " " + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER); return result; }
From source file:org.solovyev.android.messenger.sync.SyncTask.java
License:Apache License
private static boolean isTimeForChatsUpdate(@Nonnull SyncData syncData) { boolean result = false; final Account account = getAccountService().getAccountById(syncData.getAccountId()); final DateTime lastChatsSyncDate = account.getSyncData().getLastChatsSyncDate(); if (lastChatsSyncDate == null || lastChatsSyncDate.plusHours(1).isBefore(DateTime.now())) { result = true;//from ww w . j a v a2 s .c o m } return result; }
From source file:org.vaadin.spring.samples.mvp.ui.mock.MockDsrDAO.java
License:Apache License
@Override // construct data for any day up to effective date of assetOwner public List<DSRUpdateDTO> getDSRHourly(DateTime day, String assetOwner) { List<DSRUpdateDTO> result = new ArrayList<>(); DSRUpdateDTO dto = new DSRUpdateDTO(); List<DSRUpdateHourlyDTO> hourlies = new ArrayList<>(); DSRUpdateHourlyDTO h;/* w ww . j a v a 2 s. co m*/ DateTime hour; if (data.allParticipants().keySet().contains(assetOwner) && day.isBefore(MockData.TERMINATION_DATE)) { dto = new DSRUpdateDTO(); dto.getId().setDay(SSTimeUtil.dateTimeToIsoDay(day)); for (DSRUpdateHourlyDTO hourly : data.allDsrHourlyUpdates()) { if (assetOwner.equals(hourly.getId().getAssetOwner())) { h = new DSRUpdateHourlyDTO(); h.setCommitStatus(hourly.getCommitStatus()); h.setEconomicMax(hourly.getEconomicMax()); h.setEconomicMin(hourly.getEconomicMin()); h.getId().setAssetOwner(hourly.getId().getAssetOwner()); h.getId().setLocation(hourly.getId().getLocation()); int parsedHour = Integer.parseInt(hourly.getId().getHour()); if (parsedHour >= 0 && parsedHour < 24) { hour = day.plusHours(parsedHour); } else { hour = day.plusDays(1); } h.getId().setHour(SSTimeUtil.dateTimeToIsoNoMillis(hour)); hourlies.add(h); } } dto.setRecords(hourlies); result.add(dto); } return result; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
public static List<String> isoHoursForDay(final DateTime date) { final int hoursInDay = hoursInDay(date); List<String> hours = new ArrayList<String>(); for (int i = 0; i < hoursInDay; i++) { String hour = dateTimeToIsoNoMillis(date.plusHours(i + 1)); hours.add(hour);/*from w w w .j a v a 2s . com*/ } return hours; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Converts calendar day at midnight in yyyy-mm-dd format to an * org.joda.time.DateTime Format employs Market time zone. * * @param day//from w w w .ja v a 2s . c o m * a yyyy-mm-dd formatted String, * @param hour * hour in day (1-24) * @param extra * is extra or duplicate hour * * @return a DateTime instance representing day, hour and extra */ public static DateTime dayHourExtraToDateTime(final String day, int hour, boolean extra) { DateTime result = isoDateParser.parseDateTime(day); result = result.plusHours(hour); if (extra) { result = result.plusHours(1); } return result; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Calculate a minute interval based on an ISO8601 formatted String (no * millis), an hour label, and an interval label * * @param day/* www. j av a 2 s .c om*/ * an ISO8601 formatted String (no millis) * @param hour * an hour label (usually 01-24) * @param intervalLabel * an interval label (the key, 01-12) * @return a minute interval */ public static String getIntervalInIso(final String day, final String hour, final String intervalLabel) { final String isoDate = getHourInIso(day, hour); DateTime dateTime = isoToDateTime(isoDate); dateTime = dateTime.plusMinutes(Integer.parseInt(intervalLabel)); if (intervalLabel == "00") { dateTime = dateTime.plusHours(1).withMinuteOfHour(0); } return dateTimeToIsoNoMillis(dateTime); }
From source file:snowMeltingPointCaseOLD.SnowMeltingPointCase.java
License:GNU General Public License
/** * Process./*from w w w . ja va 2 s . c o m*/ * * @throws Exception the exception */ @Execute public void process() throws Exception { // This 2 operations allow to define if we are working with daily or hourly time step // if we are working with Daily time step, every time it adds to the start date a day // otherwise it adds an hour, "step increments at the end of the process // the actual date is needed to compute the actual energy index DateTime startDateTime = formatter.parseDateTime(tStartDate); DateTime date = (doHourly == false) ? startDateTime.plusDays(step) : startDateTime.plusHours(step).plusMinutes(30); // computing the reference system of the input DEM CoordinateReferenceSystem sourceCRS = inDem.getCoordinateReferenceSystem2D(); // from pixel coordinates (in coverage image) to geographic coordinates (in coverage CRS) MathTransform transf = inDem.getGridGeometry().getCRSToGrid2D(); // transform the GrifCoverage2D maps into writable rasters if (step == 0) { skyview = mapsTransform(inSkyview); energyIJanuary = mapsTransform(inInsJan); energyIFebruary = mapsTransform(inInsFeb); energyIMarch = mapsTransform(inInsMar); energyIApril = mapsTransform(inInsApr); energyIMay = mapsTransform(inInsMay); energyIJune = mapsTransform(inInsJun); } // starting from the shp file containing the stations, get the coordinate //of each station stationCoordinates = getCoordinate(inStations, fStationsid); //create the set of the coordinate of the station, so we can //iterate over the set Set<Integer> stationCoordinatesIdSet = stationCoordinates.keySet(); Iterator<Integer> idIterator = stationCoordinatesIdSet.iterator(); // trasform the list of idStation into an array idStations = stationCoordinatesIdSet.toArray(); // iterate over the list of the stations to detect their position in the // map and their latitude // iterate over the list of the stations for (int i = 0; i < idStations.length; i++) { // compute the coordinate of the station from the linked hashMap Coordinate coordinate = (Coordinate) stationCoordinates.get(idIterator.next()); // define the position, according to the CRS, of the station in the map DirectPosition point = new DirectPosition2D(sourceCRS, coordinate.x, coordinate.y); // trasform the position in two the indices of row and column DirectPosition gridPoint = transf.transform(point, null); // add the indices to a list columnStation.add((int) gridPoint.getCoordinate()[0]); rowStation.add((int) gridPoint.getCoordinate()[1]); //reproject the map in WGS84 and compute the latitude Point[] idPoint = getPoint(coordinate, sourceCRS, targetCRS); latitudeStation.add(Math.toRadians(idPoint[0].getY())); // read the input data for the given station temperature = inTemperatureValues.get(idStations[i])[0]; rainfall = inRainfallValues.get(idStations[i])[0]; snowfall = inSnowfallValues.get(idStations[i])[0]; shortwaveRadiation = inShortwaveRadiationValues.get(idStations[i])[0]; //read the input skyview for the given station position skyviewValue = skyview.getSampleDouble(columnStation.get(i), rowStation.get(i), 0); // compute the energy index, considering the two cases, daily and hourly: // if it is daily is the value in the map in the station position // if it is hourly, we have to distinguish between night and day. During night //the value is the minimum of the map, during the day is the value at the //given station position EImode = SimpleEIFactory.createModel(doHourly, date, latitudeStation.get(i), columnStation.get(i), rowStation.get(i), energyIJanuary, energyIFebruary, energyIMarch, energyIApril, energyIMay, energyIJune); EIvalue = EImode.eiValues(); // compute the melting and the discharge and stores the results into Hashmap storeResult_series((Integer) idStations[i], computeMeltingDischarge(), computeSWE()); } // upgrade the step for the date step++; }
From source file:snowMeltingRasterCase.SnowMeltingRasterCase.java
License:Open Source License
/** * Process.//from ww w .ja va 2 s.co m * * @throws Exception the exception */ @Execute public void process() throws Exception { // This 2 operations allow to define if we are working with daily or hourly time step // if we are working with Daily time step, every time it adds to the start date a day // otherwise it adds an hour, "step increments at the end of the process // the actual date is needed to compute the actual energy index DateTime startDateTime = formatter.parseDateTime(tStartDate); DateTime date = (doHourly == false) ? startDateTime.plusDays(step) : startDateTime.plusHours(step).plusMinutes(30); // computing the reference system of the input DEM CoordinateReferenceSystem sourceCRS = inDem.getCoordinateReferenceSystem2D(); // transform the GrifCoverage2D maps into writable rasters if (step == 0) { skyview = mapsReader(inSkyview); energyIJanuary = mapsReader(inInsJan); energyIFebruary = mapsReader(inInsFeb); energyIMarch = mapsReader(inInsMar); energyIApril = mapsReader(inInsApr); energyIMay = mapsReader(inInsMay); energyIJune = mapsReader(inInsJun); solidWater = 0; liquidWater = 0; } // transform the GrifCoverage2D maps into writable rasters WritableRaster temperatureMap = mapsReader(inTempGrid); WritableRaster rainfallMap = mapsReader(inRainGrid); WritableRaster snowfallMap = mapsReader(inSnowfallGrid); WritableRaster radiationMap = mapsReader(inSolarGrid); // get the dimension of the maps RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inDem); int cols = regionMap.getCols(); int rows = regionMap.getRows(); WritableRaster outMeltingWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRaster outSWEWritableRaster = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); WritableRandomIter MeltingIter = RandomIterFactory.createWritable(outMeltingWritableRaster, null); WritableRandomIter SWEIter = RandomIterFactory.createWritable(outSWEWritableRaster, null); // get the geometry of the maps and the coordinates of the stations GridGeometry2D inDemGridGeo = inDem.getGridGeometry(); stationCoordinates = getCoordinate(inDemGridGeo); // iterate over the entire domain and compute for each pixel the SWE for (int r = 1; r < rows - 1; r++) { for (int c = 1; c < cols - 1; c++) { int k = 0; // get the exact value of the variable in the pixel i, j temperature = temperatureMap.getSampleDouble(c, r, 0); rainfall = rainfallMap.getSampleDouble(c, r, 0); snowfall = snowfallMap.getSampleDouble(c, r, 0); shortwaveRadiation = radiationMap.getSampleDouble(c, r, 0); // get the coordinate of the given pixel Coordinate coordinate = (Coordinate) stationCoordinates.get(k); //compute the latitude, after a reprojection in WGS 84 Point[] idPoint = getPoint(coordinate, sourceCRS, targetCRS); latitudeStation.add(Math.toRadians(idPoint[0].getY())); // compute the energy index as in the previous case EImode = SimpleEIFactory.createModel(doHourly, date, latitudeStation.get(k), c, r, energyIJanuary, energyIFebruary, energyIMarch, energyIApril, energyIMay, energyIJune); EIvalue = EImode.eiValues(); double freezing = (temperature < meltingTemperature) ? computeFreezing() : 0; melting = (temperature > meltingTemperature) ? computeMelting() : 0; solidWater = computeSolidWater(solidWater, freezing); computeLiquidWater(liquidWater, freezing, melting); MeltingIter.setSample(c, r, 0, computeMeltingDischarge(solidWater)); SWEIter.setSample(c, r, 0, computeSWE(solidWater)); // the index k is for the loop over the list k++; } } CoverageUtilities.setNovalueBorder(outMeltingWritableRaster); CoverageUtilities.setNovalueBorder(outSWEWritableRaster); outMeltingGrid = CoverageUtilities.buildCoverage("Melting", outMeltingWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); outSWEGrid = CoverageUtilities.buildCoverage("SWE", outSWEWritableRaster, regionMap, inDem.getCoordinateReferenceSystem()); // upgrade the step for the new date step++; }
From source file:swrbPointCase.ShortwaveRadiationBalancePointCase.java
License:GNU General Public License
@Execute public void process() throws Exception { // This 2 operations allow to define if we are working with daily or hourly time step // if we are working with Daily time step, every time it adds to the start date a day // otherwise it adds an hour, "step" increments at the end of the process // the actual date is needed to compute the actual sunrise and sunset DateTime startDateTime = formatter.parseDateTime(tStartDate); DateTime date = (doHourly == false) ? startDateTime.plusDays(step) : startDateTime.plusHours(step).plusMinutes(30); // from pixel coordinates (in coverage image) to geographic coordinates (in coverage CRS) MathTransform transf = inDem.getGridGeometry().getCRSToGrid2D(); // computing the reference system of the input DEM CoordinateReferenceSystem sourceCRS = inDem.getCoordinateReferenceSystem2D(); if (step == 0) { // transform the GrifCoverage2D maps into writable rasters demWR = mapsTransform(inDem);/*w w w.j a v a2 s . c om*/ skyviewfactorWR = mapsTransform(inSkyview); // starting from the shp file containing the stations, get the coordinate //of each station stationCoordinates = getCoordinate(inStations, fStationsid); //get the dimension of the DEM and the resolution height = demWR.getHeight(); width = demWR.getWidth(); dx = CoverageUtilities.getRegionParamsFromGridCoverage(inDem).get(CoverageUtilities.XRES); // compute the vector normal to a grid cell surface. normalWR = normalVector(demWR, dx); } //create the set of the coordinate of the station, so we can //iterate over the set Iterator<Integer> idIterator = stationCoordinates.keySet().iterator(); // trasform the list of idStation into an array idStations = stationCoordinates.keySet().toArray(); // iterate over the list of the stations to detect their position in the // map and their latitude // iterate over the list of the stations for (int i = 0; i < idStations.length; i++) { // compute the coordinate of the station from the linked hashMap Coordinate coordinate = (Coordinate) stationCoordinates.get(idIterator.next()); // define the position, according to the CRS, of the station in the map DirectPosition point = new DirectPosition2D(sourceCRS, coordinate.x, coordinate.y); // trasform the position in two the indices of row and column DirectPosition gridPoint = transf.transform(point, null); // add the indices to a list columnStation.add((int) gridPoint.getCoordinate()[0]); rowStation.add((int) gridPoint.getCoordinate()[1]); //reproject the map in WGS84 and compute the latitude Point[] idPoint = getPoint(coordinate, sourceCRS, targetCRS); latitudeStation.add(Math.toRadians(idPoint[0].getY())); // read the input data for the given station temperature = defaultTemp; if (inTemperatureValues != null) temperature = inTemperatureValues.get(idStations[i])[0]; humidity = pRH; if (inHumidityValues != null) humidity = inHumidityValues.get(idStations[i])[0]; // calculating the sun vector double sunVector[] = calcSunVector(latitudeStation.get(i), getHourAngle(date, latitudeStation.get(i))); // calculate the inverse of the sun vector double[] inverseSunVector = calcInverseSunVector(sunVector); // calculate the normal of the sun vector according to Corripio (2003) double[] normalSunVector = calcNormalSunVector(sunVector); //E0 is the correction factor related to Earths orbit eccentricity computed according to Spencer (1971): double E0 = computeE0(date); //evaluate the shadow map WritableRaster shadowWR = calculateFactor(height, width, sunVector, inverseSunVector, normalSunVector, demWR, dx); // calculate the direct radiation, during the daylight double direct = (hour > (sunrise) && hour < (sunset)) ? calcDirectRadiation(columnStation.get(i), rowStation.get(i), demWR, shadowWR, sunVector, normalWR, E0, temperature, humidity) : 0; //calculate the diffuse radiation, during the daylight double diffuse = (hour > (sunrise) && hour < (sunset)) ? calcDiffuseRadiation(sunVector, E0, columnStation.get(i), rowStation.get(i)) : 0; // calculate the radiation at the top of the atmosphere, during the daylight double topATM = (hour > (sunrise) && hour < (sunset)) ? calcTopAtmosphere(E0, sunVector[2]) : 0; // calculate the radiation at the top of the atmosphere, during the daylight double total = (hour > (sunrise) && hour < (sunset)) ? direct + diffuse : 0; storeResult_series((Integer) idStations[i], direct, diffuse, topATM, total); } // upgrade the step for the date step++; }