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

The following examples show how to use org.joda.time.DateTime#getHourOfDay() . 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: 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 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: Reminder.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create default auto message for date of anniversary
 */
public Reminder(Date dateEvent, int minuteBeforeEvent) {
    this.id = ID_UNDEFINED;
    this.dateEvent = dateEvent;
    this.dateEvent = new DateTime(this.dateEvent)
            .withHourOfDay(0)
            .withMinuteOfHour(0)
            .withSecondOfMinute(0)
            .withMillisOfSecond(0)
            .toDate();
    DateTime dateReminder = new DateTime(dateEvent).minusMinutes(minuteBeforeEvent);
    this.hourOfDay = dateReminder.getHourOfDay();
    this.minuteOfHour = dateReminder.getMinuteOfHour();
    this.daysBefore = Days.daysBetween(dateReminder, new DateTime(dateEvent)).getDays();
    if(minuteBeforeEvent > 0)
        this.daysBefore++;
}
 
Example 4
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 5
Source File: Date.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
public Date(DateTime dateTime) {

        this.year = dateTime.getYear();
        this.monthOfYear = dateTime.getMonthOfYear();
        this.dayOfWeek = dateTime.getDayOfWeek();
        this.dayOfMonth = dateTime.getDayOfMonth();
        this.hourOfDay = dateTime.getHourOfDay();
        this.minuteOfHour = dateTime.getMinuteOfHour();
        this.minuteOfDay = dateTime.getMinuteOfDay();
        this.weekOfYear = dateTime.getWeekOfWeekyear();
    }
 
Example 6
Source File: WeatherFragment.java    From OpenWeatherPlus-Android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetTextI18n")
@Override
public void getWeatherNow(Now bean) {
    if (bean != null && bean.getNow() != null) {
        NowBase now = bean.getNow();
        String rain = now.getPcpn();
        String hum = now.getHum();
        String pres = now.getPres();
        String vis = now.getVis();
        String windDir = now.getWind_dir();
        String windSc = now.getWind_sc();
        String condTxt = now.getCond_txt();
        condCode = now.getCond_code();
        nowTmp = now.getTmp();
        tvCond.setText(condTxt);
        tvTmp.setText(nowTmp + "°");
        if (ContentUtil.APP_SETTING_UNIT.equals("hua")) {
            tvTmp.setText(TransUnitUtil.getF(nowTmp) + "°");
        }
        tvTodayRain.setText(rain + "mm");
        tvTodayPressure.setText(pres + "HPA");
        tvTodayHum.setText(hum + "%");
        tvTodayVisible.setText(vis + "KM");
        tvWindDir.setText(windDir);
        tvWindSc.setText(windSc + "级");
        DateTime nowTime = DateTime.now();
        int hourOfDay = nowTime.getHourOfDay();
        if (hourOfDay > 6 && hourOfDay < 19) {
            ivBack.setImageResource(IconUtils.getDayBack(condCode));
        } else {
            ivBack.setImageResource(IconUtils.getNightBack(condCode));
        }
        if (isEn) {
            tvWindSc.setText("Level" + windSc);
        }
        swipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 7
Source File: MDateAndTime.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Decode {@code encodedTimestamp} using the {@code tz} timezone. */
public static long[] decodeTimestamp(long encodedTimestamp, String tz)  {
    DateTime dt = new DateTime(encodedTimestamp * 1000L, DateTimeZone.forID(tz));
    return new long[] {
        dt.getYear(),
        dt.getMonthOfYear(),
        dt.getDayOfMonth(),
        dt.getHourOfDay(),
        dt.getMinuteOfHour(),
        dt.getSecondOfMinute()
    };
}
 
Example 8
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 9
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOGetHour() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "getHour");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getHourOfDay();
            if (val == -1) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 10
Source File: TimestampFormatter.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    int hourOfDay = timestamp.getHourOfDay() % 12;
    if (hourOfDay == 0) {
        hourOfDay = 12;
    }
    return zeroPadded(2, String.valueOf(hourOfDay));
}
 
Example 11
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 12
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 13
Source File: PvPArenaService.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isGloryArenaAvailable() {
	DateTime now = DateTime.now();
	int hour = now.getHourOfDay();
	int day = now.getDayOfWeek();
	return (day == 6 || day == 7) && hour >= 20 && hour < 22;
}
 
Example 14
Source File: StringByTime.java    From jianshi with Apache License 2.0 4 votes vote down vote up
private static String getStringFromDataset(Map<TimeRange, String> dataSet) {
  DateTime now = new DateTime();
  int currentHour = now.getHourOfDay();
  return dataSet.get(TimeRange.getType(currentHour));
}
 
Example 15
Source File: MapperHourOfDay.java    From warp10-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Object getDateTimeInfo(DateTime dt, long tick) {
  return dt.getHourOfDay();
}
 
Example 16
Source File: TimestampFormatter.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    int hourOfDay = timestamp.getHourOfDay() % 24;
    return zeroPadded(2, String.valueOf(hourOfDay));
}
 
Example 17
Source File: TimestampFormatter.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public String format(DateTime timestamp) {
    // TODO: verify correctness
    return timestamp.getHourOfDay() < 12 ? "AM" : "PM";
}
 
Example 18
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalRevokeTherapeuticLinkRequest(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 RevokeTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request), (TherapeuticLink)null, (Proof[])null);
}
 
Example 19
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalPutTherapeuticLinkRequest(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 PutTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor((AuthorType)request.getAuthor()));
}
 
Example 20
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());
}