List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:org.talend.components.netsuite.client.model.search.SearchDateFieldAdapter.java
License:Open Source License
protected XMLGregorianCalendar convertDateTime(String input) { String valueToParse = input;// www .j a va2 s . c om String dateTimeFormatPattern = dateFormatPattern + " " + timeFormatPattern; if (input.length() == dateFormatPattern.length()) { dateTimeFormatPattern = dateFormatPattern; } else if (input.length() == timeFormatPattern.length()) { DateTime dateTime = new DateTime(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormatPattern); valueToParse = dateFormatter.print(dateTime) + " " + input; } DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPattern); DateTime dateTime; try { dateTime = dateTimeFormatter.parseDateTime(valueToParse); } catch (IllegalArgumentException e) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.searchDateField.invalidDateTimeFormat", valueToParse)); } XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
From source file:org.tanrabad.survey.utils.time.DateTimePrinter.java
License:Apache License
@Override public String print(long referenceTime) { DateTime currentTimeInMills = new DateTime(currentTimer.getInMills()); DateTime agoDateTime = new DateTime(referenceTime); if (currentTimeInMills.getYear() == agoDateTime.getYear()) return String.format(Locale.US, "%d %s %02d:%02d", agoDateTime.getDayOfMonth(), monthNameMap.get(agoDateTime.getMonthOfYear()), agoDateTime.getHourOfDay(), agoDateTime.getMinuteOfHour()); else {//from www.j a v a 2 s . c o m return String.format(Locale.US, "%d %s %04d %02d:%02d", agoDateTime.getDayOfMonth(), monthNameMap.get(agoDateTime.getMonthOfYear()), agoDateTime.getYear() + 543, agoDateTime.getHourOfDay(), agoDateTime.getMinuteOfHour()); } }
From source file:org.tanrabad.survey.utils.time.DaysAgoPrinter.java
License:Apache License
@Override public String print(long referenceTime) { DateTime currentTimeInMills = new DateTime(currentTimer.getInMills()); DateTime agoDateTime = new DateTime(referenceTime); if (currentTimeInMills.getDayOfYear() - agoDateTime.getDayOfYear() == 1) { DateTime dateTime = new DateTime(referenceTime); return String.format(Locale.US, " %02d:%02d", dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); }//from ww w .j ava2 s .c o m return null; }
From source file:org.traccar.protocol.H02ProtocolEncoder.java
License:Apache License
private Object formatCommand(DateTime time, String uniqueId, String type, String... params) { StringBuilder result = new StringBuilder(String.format("*%s,%s,%s,%02d%02d%02d", MARKER, uniqueId, type, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute())); for (String param : params) { result.append(",").append(param); }//from w w w .j a v a 2 s .c o m result.append("#"); return result.toString(); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Return the starting day accounting for Hour 00:00:00 being the day after. * * @param isoHour// ww w .jav a2 s .c o m * an iso String * @return an iso String */ public static String isoHourEndingToIsoDay(String isoHour) { DateTime dt = isoToDateTime(isoHour); dt = dt.withZone(SSTimeUtil.getMarketTimeZone()); if (dt.getHourOfDay() == 0) { dt = dt.minusDays(1); } return dateTimeToIsoDay(dt); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Return the starting day accounting for Hour 00:00:00 being the day after. * The date is coerced into the market time zone before computing the hour * When hour 00 is detected the day is decremented. The returned date has a * time of 00:00:00 in the market time zone. * * @param dt/*from www .j av a2 s. c om*/ * an org.joda.time.DateTime * @return an org.joda.time.DateTime expressing an operating day */ public static DateTime getOperatingDay(DateTime dt) { dt = dt.withZone(SSTimeUtil.getMarketTimeZone()); if (dt.getHourOfDay() == 0) { dt = dt.minusDays(1); } return dt.withMillisOfDay(0); }
From source file:org.wicketstuff.calendarviews.LargeView.java
License:Apache License
protected final ListView<IEvent> createEventListView(String id, final IModel<DateMidnight> dateModel, final int cellsLeftInRow, IModel<List<IEvent>> model) { return new ListView<IEvent>(id, model) { private static final long serialVersionUID = 1L; @Override//from w w w .ja va 2 s . c o m protected void populateItem(final ListItem<IEvent> item) { WebMarkupContainer link = createEventLink("link", item.getModel()); link.add(createStartTimeLabel("startTime", item.getModel())); link.add(new Label("title", new PropertyModel<String>(item.getModel(), "title"))); item.add(link); // things to decorate the item itself item.add(new HowManyDaysClassBehavior(dateModel, cellsLeftInRow, item.getModel())); item.add(new AddCssClassBehavior(item.getModel())); } private Label createStartTimeLabel(String id, final IModel<IEvent> model) { return new Label(id, new LoadableDetachableModel<String>() { private static final long serialVersionUID = 1L; @Override protected String load() { // TODO : make this implementation more // internationalized... this one is too static // use dateformat or something DateTime start = new DateTime(model.getObject().getStartTime()); StringBuffer sb = new StringBuffer(); int hr = start.getHourOfDay(); sb.append(hr > 12 ? hr - 12 : hr); int min = start.getMinuteOfHour(); if (min != 0) { sb.append(':'); if (min < 0) { sb.append('0'); } sb.append(min); } sb.append(hr > 12 ? 'p' : 'a'); return sb.toString(); } }) { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return model.getObject().isAllDayEvent() == false; } }; } }; }
From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java
License:Open Source License
@Override public List<Result<ExecutionTimeOfAPIValues>> getExecutionTimeByAPI(String apiName, String version, String tenantDomain, String fromDate, String toDate, String drillDown, String mediationType) throws APIMgtUsageQueryServiceClientException { List<Result<ExecutionTimeOfAPIValues>> result = new ArrayList<Result<ExecutionTimeOfAPIValues>>(); try {/* ww w . j ava 2s .c om*/ StringBuilder query = new StringBuilder( "from " + APIUsageStatisticsClientConstants.API_EXECUTION_TIME_AGG + " on(" + APIUsageStatisticsClientConstants.API_NAME + "=='" + apiName + "'"); if (version != null) { query.append(" AND " + APIUsageStatisticsClientConstants.API_VERSION + "=='" + version + "'"); } if (tenantDomain != null) { query.append(" AND " + APIUsageStatisticsClientConstants.API_CREATOR_TENANT_DOMAIN + "=='" + tenantDomain + "'"); } if (fromDate != null && toDate != null) { String granularity = APIUsageStatisticsClientConstants.SECONDS_GRANULARITY; Map<String, Integer> durationBreakdown = this.getDurationBreakdown(fromDate, toDate); LocalDateTime currentDate = LocalDateTime.now(DateTimeZone.UTC); DateTimeFormatter formatter = DateTimeFormat .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN); LocalDateTime fromLocalDateTime = LocalDateTime.parse(fromDate, formatter);//GMT time if (fromLocalDateTime.isBefore(currentDate.minusYears(1))) { granularity = APIUsageStatisticsClientConstants.MONTHS_GRANULARITY; } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_MONTHS) > 0 || durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_WEEKS) > 0) { granularity = APIUsageStatisticsClientConstants.DAYS_GRANULARITY; } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_DAYS) > 0) { granularity = APIUsageStatisticsClientConstants.HOURS_GRANULARITY; } else if (durationBreakdown.get(APIUsageStatisticsClientConstants.DURATION_HOURS) > 0) { granularity = APIUsageStatisticsClientConstants.MINUTES_GRANULARITY; } query.append(") within " + getTimestamp(fromDate) + "L, " + getTimestamp(toDate) + "L per '" + granularity + "'"); } else { query.append(") within " + 0 + "L, " + new Date().getTime() + "L per 'months'"); } query.append(" select " + APIUsageStatisticsClientConstants.API_NAME + ", " + APIUsageStatisticsClientConstants.API_CONTEXT + ", " + APIUsageStatisticsClientConstants.API_CREATOR + ", " + APIUsageStatisticsClientConstants.API_VERSION + ", " + APIUsageStatisticsClientConstants.TIME_STAMP + ", " + APIUsageStatisticsClientConstants.RESPONSE_TIME + ", " + APIUsageStatisticsClientConstants.SECURITY_LATENCY + ", " + APIUsageStatisticsClientConstants.THROTTLING_LATENCY + ", " + APIUsageStatisticsClientConstants.REQUEST_MEDIATION_LATENCY + ", " + APIUsageStatisticsClientConstants.RESPONSE_MEDIATION_LATENCY + ", " + APIUsageStatisticsClientConstants.BACKEND_LATENCY + ", " + APIUsageStatisticsClientConstants.OTHER_LATENCY + ";"); JSONObject jsonObj = APIUtil.executeQueryOnStreamProcessor( APIUsageStatisticsClientConstants.APIM_ACCESS_SUMMARY_SIDDHI_APP, query.toString()); long timeStamp; if (jsonObj != null) { JSONArray jArray = (JSONArray) jsonObj.get(APIUsageStatisticsClientConstants.RECORDS_DELIMITER); for (Object record : jArray) { JSONArray recordArray = (JSONArray) record; if (recordArray.size() == 12) { Result<ExecutionTimeOfAPIValues> result1 = new Result<ExecutionTimeOfAPIValues>(); ExecutionTimeOfAPIValues executionTimeOfAPIValues = new ExecutionTimeOfAPIValues(); executionTimeOfAPIValues.setApi((String) recordArray.get(0)); executionTimeOfAPIValues.setContext((String) recordArray.get(1)); executionTimeOfAPIValues.setApiPublisher((String) recordArray.get(2)); executionTimeOfAPIValues.setVersion((String) recordArray.get(3)); timeStamp = (Long) recordArray.get(4); DateTime time = new DateTime(timeStamp).withZone(DateTimeZone.UTC); executionTimeOfAPIValues.setYear(time.getYear()); executionTimeOfAPIValues.setMonth(time.getMonthOfYear()); executionTimeOfAPIValues.setDay(time.getDayOfMonth()); executionTimeOfAPIValues.setHour(time.getHourOfDay()); executionTimeOfAPIValues.setMinutes(time.getMinuteOfHour()); executionTimeOfAPIValues.setSeconds(time.getSecondOfMinute()); executionTimeOfAPIValues.setApiResponseTime((Long) recordArray.get(5)); executionTimeOfAPIValues.setSecurityLatency((Long) recordArray.get(6)); executionTimeOfAPIValues.setThrottlingLatency((Long) recordArray.get(7)); executionTimeOfAPIValues.setRequestMediationLatency((Long) recordArray.get(8)); executionTimeOfAPIValues.setResponseMediationLatency((Long) recordArray.get(9)); executionTimeOfAPIValues.setBackendLatency((Long) recordArray.get(10)); executionTimeOfAPIValues.setOtherLatency((Long) recordArray.get(11)); result1.setValues(executionTimeOfAPIValues); result1.setTableName(APIUsageStatisticsClientConstants.API_EXECUTION_TIME_AGG); result1.setTimestamp(RestClientUtil.longToDate(new Date().getTime())); result.add(result1); } } } if (!result.isEmpty() && fromDate != null && toDate != null) { insertZeroElementsAndSort(result, drillDown, getDateToLong(fromDate), getDateToLong(toDate)); } } catch (APIManagementException e) { handleException("Error occurred while querying from Stream Processor ", e); } catch (ParseException e) { handleException("Couldn't parse the date", e); } return result; }
From source file:org.xmlcml.euclid.JodaDate.java
License:Apache License
@SuppressWarnings("deprecation") public static Date parseJodaDate(DateTime jodaDate) { int year = jodaDate.getYear(); int month = jodaDate.getMonthOfYear(); int day = jodaDate.getDayOfMonth(); int hour = jodaDate.getHourOfDay(); int min = jodaDate.getMinuteOfDay(); int sec = jodaDate.getSecondOfMinute(); // arghh// ww w . ja v a 2 s .com Date date = new Date(year - 1900, month, day, hour, min, sec); return date; }
From source file:ph.fingra.statisticsweb.common.util.DateTimeUtil.java
License:Apache License
public static String[] getDashboardFromToWithPrev(String numType) { int num = Integer.parseInt(numType.substring(0, numType.length() - 1)); String type = numType.substring(numType.length() - 1).toLowerCase(); final DateTime now = DateTime.now(); final DateTime to = now.minusDays(1); final DateTime from = type.equals("w") ? to.minusDays(num * 7 - 1) : (type.equals("m") ? to.minusMonths(num) : to.withMonthOfYear(1).withDayOfMonth(1)); final DateTime prevTo = type.equals("y") ? to.minusYears(1) : from.minusDays(1); final DateTime prevFrom = type.equals("w") ? prevTo.minusDays(num * 7 - 1) : (type.equals("m") ? prevTo.minusMonths(num) : prevTo.withMonthOfYear(1).withDayOfMonth(1)); final DateTime yesterday = now.minusDays(1); final DateTime beforeYesterday = now.minusDays(2); String nowTime = ""; String prevTime = ""; // before or after 10 minutes if (now.getMinuteOfHour() < 10) { // before 10 minutes String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp; String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); } else { // after 10 minutes nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay()) : String.valueOf(now.getHourOfDay()); String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); }//from w ww . java 2 s. c om return new String[] { from.toString("yyyy-MM-dd"), to.toString("yyyy-MM-dd"), prevFrom.toString("yyyy-MM-dd"), prevTo.toString("yyyy-MM-dd"), yesterday.toString("yyyy-MM-dd"), beforeYesterday.toString("yyyy-MM-dd"), now.toString("yyyy-MM-dd"), nowTime, prevTime }; }