List of usage examples for org.joda.time DateTime dayOfMonth
public Property dayOfMonth()
From source file:org.segrada.util.FlexibleDateParser.java
License:Apache License
/** * Parse input to Julian Day number// w w w . ja v a2 s .c om * @param input string * @param type calendar type, e.g. "G" or "J" * @param high true to get last instance of parsed time, first otherwise * @return julian day number */ public Long inputToJd(@Nullable String input, String type, boolean high) { // sanity check if (input == null || "".equals(input)) return high ? Long.MAX_VALUE : Long.MIN_VALUE; try { DateTime date = inputFormatter.withChronology(getChronologyFromType(type)) .withLocale(Locale.getDefault()).withZoneUTC().parseDateTime(input); // get last time instance of the input if (high) { // guess input pattern by counting character occurences int count = Math.max(StringUtils.countMatches(input, "."), Math.max(StringUtils.countMatches(input, "/"), StringUtils.countMatches(input, "-"))); if (count == 0) // year only date = date.withMonthOfYear(12).withDayOfMonth(31); else if (count == 1) { // year/month date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); } // day/month/year as is } return DateTimeUtils.toJulianDayNumber(date.getMillis()); } catch (Exception e) { logger.warn("Could not parse to DateTime: " + input + " (type = " + type + ")", e); } return null; }
From source file:org.shadowmask.core.mask.rules.generalizer.impl.TimestampGeneralizer.java
License:Apache License
@Override public Long generalize(Long timestamp, int hierarchyLevel) { if (timestamp == null) { return null; }/*from ww w. ja v a2 s . c om*/ if (hierarchyLevel > ROOT_HIERARCHY_LEVEL || hierarchyLevel < 0) { throw new MaskRuntimeException("Root hierarchy level of MobileGeneralizer is " + ROOT_HIERARCHY_LEVEL + ", invalid input hierarchy level[" + hierarchyLevel + "]"); } if (hierarchyLevel == 0) { return timestamp; } try { DateTime dateTime = new DateTime(timestamp); switch (hierarchyLevel) { // mask ms. case 1: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute()); break; // mask second. case 2: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); break; // mask minute. case 3: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); break; // mask hour. case 4: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); break; // mask day. case 5: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); break; // mask month. case 6: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); dateTime = dateTime.monthOfYear().setCopy(1); break; // mask year. case 7: dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); dateTime = dateTime.minuteOfHour().setCopy(0); dateTime = dateTime.hourOfDay().setCopy(0); dateTime = dateTime.dayOfMonth().setCopy(1); dateTime = dateTime.monthOfYear().setCopy(1); dateTime = dateTime.year().setCopy(1901); break; } return dateTime.getMillis(); } catch (Throwable e) { throw new MaskRuntimeException("Invalid timestamp to generalize:" + timestamp, e); } }
From source file:org.softdays.mandy.service.support.CalendarServiceImpl.java
License:Open Source License
@Override public DateTime getFirstMondayOfMonth(final DateTime givenDate) { DateTime date = givenDate.dayOfMonth().withMinimumValue(); while (!this.isMonday(date)) { date = date.plusDays(1);//from w w w .j a v a 2s . c om } return date; }
From source file:org.softdays.mandy.service.support.CalendarServiceImpl.java
License:Open Source License
@Override public DateTime getFirstSundayAfterEndOfMonth(final DateTime givenDate) { DateTime date = givenDate.dayOfMonth().withMaximumValue(); while (date.getDayOfWeek() != DateTimeConstants.SUNDAY) { date = date.plusDays(1);//from w w w. j av a 2s. c o m } return date; }
From source file:org.springframework.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getDayCountsForMonth(String name, DateTime month) { AggregateKeyGenerator akg = new AggregateKeyGenerator(AGGREGATE_COUNTER_KEY_PREFIX, name, month.withTimeAtStartOfDay()); return convertToArray(getEntries(akg.getMonthKey()), month.dayOfMonth().getMaximumValue(), true); // Days in this month }
From source file:org.springframework.cloud.stream.app.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getDayCountsForMonth(String name, DateTime month) { AggregateKeyGenerator akg = new AggregateKeyGenerator(REPO_PREFIX, name, month.withTimeAtStartOfDay()); return convertToArray(getEntries(akg.getMonthKey()), month.dayOfMonth().getMaximumValue(), true); // Days in this month }
From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
private long[] getDayCountsForMonth(String name, DateTime month) { AggregateKeyGenerator akg = new AggregateKeyGenerator(getPrefix(), name, month.withTimeAtStartOfDay()); return convertToArray(getEntries(akg.getMonthKey()), month.dayOfMonth().getMaximumValue(), true); // Days in this month }
From source file:org.trakhound.www.trakhound.device_details.DeviceStatus.java
License:Open Source License
public static DeviceStatus get(UserConfiguration userConfig, String uniqueId) { if (userConfig != null) { DateTime now = DateTime.now(); DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0);//w ww . j a va 2 s . c om DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + userConfig.sessionToken + "&sender_id=" + UserManagement.getSenderId() + "&devices=[{\"unique_id\":\"" + uniqueId + "\"}]" + "&from=" + fromStr + "&to=" + toStr + "&command=" + "01111"; // Get Status, Controller, Oee, and Timers tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { try { JSONArray a = new JSONArray(response); if (a.length() > 0) { JSONObject obj = a.getJSONObject(0); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.controllerInfo = ControllerInfo.parse(obj.getJSONObject("controller")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); deviceStatus.timersInfo = TimersInfo.parse(obj.getJSONObject("timers")); return deviceStatus; } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } } } return null; }
From source file:org.trakhound.www.trakhound.device_list.DeviceStatus.java
License:Open Source License
public static DeviceStatus[] get(UserConfiguration userConfig) { if (userConfig != null) { try {/*from w w w . j a v a2s .co m*/ DateTime now = DateTime.now(); DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0); DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + URLEncoder.encode(userConfig.sessionToken, "UTF-8") + "&sender_id=" + URLEncoder.encode(UserManagement.getSenderId(), "UTF-8") + "&from=" + fromStr + "&to=" + toStr + "&command=0101"; // Get Status and Oee tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { ArrayList<DeviceStatus> devicesStatuses = new ArrayList<>(); try { JSONArray a = new JSONArray(response); for (int i = 0; i < a.length(); i++) { JSONObject obj = a.getJSONObject(i); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); devicesStatuses.add(deviceStatus); } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } DeviceStatus[] deviceStatusArray = new DeviceStatus[devicesStatuses.size()]; return devicesStatuses.toArray(deviceStatusArray); } } catch (UnsupportedEncodingException ex) { Log.d("Exception", ex.getMessage()); } } return null; }
From source file:org.tylproject.vaadin.addon.fieldbinder.behavior.DefaultFilterFactory.java
License:Apache License
private static Date monthDatePatternToDate(String pattern, RangeEndpoint rangeEndpoint) { String[] patternComponents = pattern.split(dateSepPattern.pattern()); int y = Integer.parseInt(patternComponents[1]); int mm = Integer.parseInt(patternComponents[0]); DateTime dt = new DateTime(y, mm, 1, 0, 0); return rangeEndpoint == RangeEndpoint.Min ? dt.toDate() : new DateTime(y, mm, dt.dayOfMonth().getMaximumValue(), 23, 59, 59, 999).toDate(); }