Java Code Examples for org.joda.time.DateTime#getMinuteOfHour()

The following examples show how to use org.joda.time.DateTime#getMinuteOfHour() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnomalyDetectorWrapper.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * round this time to earlier boundary, depending on granularity of dataset
 * e.g. 12:15pm on HOURLY dataset should be treated as 12pm
 * any dataset with granularity finer than HOUR, will be rounded as per function frequency (assumption is that this is in MINUTES)
 * so 12.53 on 5 MINUTES dataset, with function frequency 15 MINUTES will be rounded to 12.45
 * See also {@link DetectionJobSchedulerUtils#getBoundaryAlignedTimeForDataset(DateTime, TimeUnit)}
 */
private long getBoundaryAlignedTimeForDataset(DateTime currentTime) {
  TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(dataset);
  TimeUnit dataUnit = timeSpec.getDataGranularity().getUnit();

  // For nMINUTE level datasets, with frequency defined in nMINUTES in the function, (make sure size doesnt exceed 30 minutes, just use 1 HOUR in that case)
  // Calculate time periods according to the function frequency
  if (dataUnit.equals(TimeUnit.MINUTES) || dataUnit.equals(TimeUnit.MILLISECONDS) || dataUnit.equals(
      TimeUnit.SECONDS)) {
    if (functionFrequency.getUnit().equals(TimeUnit.MINUTES) && (functionFrequency.getSize() <= 30)) {
      int minuteBucketSize = functionFrequency.getSize();
      int roundedMinutes = (currentTime.getMinuteOfHour() / minuteBucketSize) * minuteBucketSize;
      currentTime = currentTime.withTime(currentTime.getHourOfDay(), roundedMinutes, 0, 0);
    } else {
      currentTime = DetectionJobSchedulerUtils.getBoundaryAlignedTimeForDataset(currentTime,
          TimeUnit.HOURS); // default to HOURS
    }
  } else {
    currentTime = DetectionJobSchedulerUtils.getBoundaryAlignedTimeForDataset(currentTime, dataUnit);
  }

  return currentTime.getMillis();
}
 
Example 2
Source File: DateTimeWidget.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public void setAnswer() {

        if (mPrompt.getAnswerValue() != null) {

            DateTime ldt =
                    new DateTime(
                            ((Date)getCurrentAnswer().getValue()).getTime());
            mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(),
                    mDateListener);

            int altVal = ldt.getHourOfDay() == 1 ? 2 : 1;
            mTimePicker.setCurrentHour(altVal);
            mTimePicker.setCurrentHour(ldt.getHourOfDay());

            altVal = ldt.getMinuteOfHour() == 1 ? 2 : 1;
            mTimePicker.setCurrentMinute(altVal);
            mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());


        } else {
            // create time widget with current time as of right now
            clearAnswer();
        }

        widgetEntryChanged();
    }
 
Example 3
Source File: TimeWidget.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
public void setAnswer() {
    // If there's an answer, use it.
    if (mPrompt.getAnswerValue() != null) {

        // create a new date time from date object using default time zone
        DateTime ldt =
                new DateTime(((Date)getCurrentAnswer().getValue()).getTime());
        Log.d(TAG, "retrieving:" + ldt);

        int altVal = ldt.getHourOfDay() == 1 ? 2 : 1;
        mTimePicker.setCurrentHour(altVal);
        mTimePicker.setCurrentHour(ldt.getHourOfDay());

        altVal = ldt.getMinuteOfHour() == 1 ? 2 : 1;
        mTimePicker.setCurrentMinute(altVal);
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
    } else {
        // create time widget with current time as of right now
        clearAnswer();
    }
}
 
Example 4
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 5
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevokeTherapeuticLinkResponse mapXMLToRevokeTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   RevokeTherapeuticLinkResponse response = new RevokeTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalRevokeTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 6
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public GetTherapeuticLinkResponse mapXMLToGetTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   GetTherapeuticLinkResponse response = new GetTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalGetTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapListOfTherapeuticLinks(jaxbResponse.getTherapeuticlinklist()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 7
Source File: AlarmContentUtils.java    From sleep-cycle-alarm with GNU General Public License v3.0 5 votes vote down vote up
private static String getFormattedTime(DateTime date) {
    long hour = date.getHourOfDay();
    long minute = date.getMinuteOfHour();
    return getFormattedHourOrMinute(hour)
            + ":"
            + getFormattedHourOrMinute(minute);
}
 
Example 8
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevokeTherapeuticLinkResponse mapXMLToRevokeTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   RevokeTherapeuticLinkResponse response = new RevokeTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalRevokeTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 9
Source File: HistoricalData.java    From iMetrica with GNU General Public License v3.0 5 votes vote down vote up
static int getTime(DateTime t)
{
  int tot;
  int hour = t.getHourOfDay();
  int min = t.getMinuteOfHour();
  
  tot = hour*10000 + (min)*100;
  
  return tot; 
}
 
Example 10
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevokeTherapeuticLinkResponse mapXMLToRevokeTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   RevokeTherapeuticLinkResponse response = new RevokeTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalRevokeTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 11
Source File: GanttDiagramTagLib.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int calculateTimeOfDay(DateTime time) {

        int hourOfDay = time.getHourOfDay();
        int minuteOfHour = time.getMinuteOfHour();

        switch (getViewTypeEnum()) {

        case WEEKLY:

            // unit = 15 minutes
            int result = (hourOfDay + 1) * 2;
            if (minuteOfHour <= 30) {
                return result - 1;
            } else {
                return result;
            }

        case DAILY:

            // unit = 5 minutes
            for (int i = 1, j = 0; j < 60; j += 5, i++) {
                if (minuteOfHour < j + 5) {
                    return i + (12 * hourOfDay);
                }
            }

        case MONTHLY:

            // unit = hour of day
            return hourOfDay;

        case YEAR_DAILY:

            // unit = hour of day
            return hourOfDay;

        default:
            return 0;
        }
    }
 
Example 12
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public HasTherapeuticLinkResponse mapXMLToHasTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   HasTherapeuticLinkResponse response = new HasTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalHasTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 13
Source File: ViewAllRoomsSchedulesDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
private int getHourOffSet(final DateTime dateTime) {
    final int hour = dateTime.getHourOfDay();
    final int minutes = dateTime.getMinuteOfHour();
    final int minutesOffSet = minutes < 30 ? 0 : 1;
    return ((hour - 8) * 2) + minutesOffSet;
}
 
Example 14
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 15
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalHasTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new HasTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor((AuthorType)request.getAuthor()), (TherapeuticLink)null);
}
 
Example 16
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 17
Source File: TimeUtils.java    From sleep-cycle-alarm with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isRoundToHalfOfTenNeeded(DateTime dt) {
    int minuteOfMinutesOfHour = dt.getMinuteOfHour() % 10;
    return minuteOfMinutesOfHour >= 3 && minuteOfMinutesOfHour <= 7;
}
 
Example 18
Source File: DateTimeUtil.java    From cloudhopper-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest specified period in minutes. For example, if
 * a period of 5 minutes is requested, a time of "2009-06-24 13:24:51.476 -8:00"
 * would return a datetime of "2009-06-24 13:20:00.000 -8:00". The time zone of the
 * returned DateTime instance will be the same as the argument. Similar to a
 * floor() function on a float.<br>
 * NOTE: While any period in minutes between 1 and 59 can be passed into this
 * method, its only useful if the value can be evenly divided into 60 to make
 * it as useful as possible.<br>
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>5: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:35:00.000 -8:00"
 *      <li>10: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00"
 *      <li>15: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00"
 *      <li>20: "2009-06-24 13:39:51.476 UTC" -> "2009-06-24 13:20:00.000 UTC"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest period in minutes.
 */
public static DateTime floorToMinutePeriod(DateTime value, int periodInMinutes) {
    if (value == null) {
        return null;
    }
    if (periodInMinutes <= 0 || periodInMinutes > 59) {
        throw new IllegalArgumentException("period in minutes must be > 0 and <= 59");
    }
    int min = value.getMinuteOfHour();
    min = (min / periodInMinutes) * periodInMinutes;
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), min, 0, 0, value.getZone());
}
 
Example 19
Source File: DateUtil.java    From Mycat2 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象分钟数
 * @param date
 * @return
 */
public static int getMinute(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getMinuteOfHour();
}
 
Example 20
Source File: DateUtil.java    From Mycat2 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象分钟数
 * @param date
 * @return
 */
public static int getMinute(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getMinuteOfHour();
}