Example usage for org.joda.time DateTime getMinuteOfHour

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

Introduction

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

Prototype

public int getMinuteOfHour() 

Source Link

Document

Get the minute of hour field value.

Usage

From source file:org.rockholla.date.DateUtility.java

License:Open Source License

/**
 * Returns a unique string based on a timestamp (DateTime must be precise to the second
 * to ensure uniqueness)//w  w w .j  a va2s.c o  m
 * 
 * @param dateTime   the org.joda.time.DateTime to use to create the ID
 * @return         a unique string representation of the date
 */
public static String getTimestampId(DateTime dateTime) {

    String id = "";

    id = NumberUtility.format(dateTime.getYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + 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)
            + NumberUtility.format(dateTime.getMillisOfSecond(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER);

    return id;

}

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;
    }// w ww.j  a  va2  s. c o  m

    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.talend.components.netsuite.AbstractNetSuiteTestBase.java

License:Open Source License

protected static XMLGregorianCalendar composeDateTime() throws Exception {
    DateTime dateTime = DateTime.now();

    XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
    xts.setYear(dateTime.getYear());// w w  w.  j  a v  a  2 s .  c  o m
    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().getRawOffset() / 60000);

    return xts;

}

From source file:org.talend.components.netsuite.client.model.search.SearchDateFieldAdapter.java

License:Open Source License

protected XMLGregorianCalendar convertDateTime(String input) {
    String valueToParse = input;/*from  w  ww .j a va 2  s.  c  o m*/
    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  w ww .ja v a2 s  .  c  om*/
        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   w  ww  .  j  a  v a  2 s .  co 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);
    }/*w w  w. j  a v  a2 s.c  o  m*/

    result.append("#");

    return result.toString();
}

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/*  w ww .ja v a 2 s.c  om*/
        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 {// w ww  . j a va2s  .c  o m
        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: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   www .java  2 s .c o  m*/

    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 };
}