Java Code Examples for java.util.Date#setHours()

The following examples show how to use java.util.Date#setHours() . 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: AppointmentUpcomingList.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View listViewItem = inflater.inflate(R.layout.layout_appointment_list, null, true);

    TextView textViewName = (TextView) listViewItem.findViewById(R.id.clinicName);
    TextView textViewDate = (TextView) listViewItem.findViewById(R.id.dateTime);
    TextView textViewService = (TextView) listViewItem.findViewById(R.id.clinicService);

    Booking booking = bookings.get(position);
    textViewName.setText(booking.getClinic().getName());
    String pattern = "yyyy-MM-dd HH:mm ";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    Date showDate = new Date();
    showDate.setHours(booking.getTime().getHours());
    showDate.setMinutes(booking.getTime().getMinutes());
    showDate.setDate(booking.getTime().getDate());
    showDate.setMonth(booking.getTime().getMonth());
    showDate.setYear(booking.getTime().getYear());

    String date = simpleDateFormat.format(showDate);
    textViewDate.setText(date);
    textViewService.setText(booking.getService().getName());
    return listViewItem;
}
 
Example 2
Source File: EventRepositoryImplIntegrationTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
public void getLoggedEvents_WithLoggedEventsMoreThanGivenSize_ShouldReturnListOfGivenSize()
{
    for (int i = 0; i < 6; i++) {
        le = buildLoggedEvent(project, user.getUsername(), 
                EVENT_TYPE_RECOMMENDER_EVALUATION_EVENT, new Date(), -1, DETAIL_JSON);
        Date d = new Date();
        d.setHours(i);
        le.setCreated(d);
        sut.create(le);
    }

    List<LoggedEvent> loggedEvents = sut.listLoggedEventsForRecommender(project,
            user.getUsername(), EVENT_TYPE_RECOMMENDER_EVALUATION_EVENT, 5, RECOMMENDER_ID);

    assertThat(loggedEvents).as("Check that the number of logged events is 5").hasSize(5);
}
 
Example 3
Source File: ConvertToOffsetDateTimeUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDate_whenHasOffset_thenConvertWithOffset() {
    TimeZone prevTimezone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    Date date = new Date();
    date.setHours(6);
    date.setMinutes(30);

    OffsetDateTime odt = ConvertToOffsetDateTime.convert(date, 3, 30);
    assertEquals(10, odt.getHour());
    assertEquals(0, odt.getMinute());

    // Reset the timezone to its original value to prevent side effects
    TimeZone.setDefault(prevTimezone);
}
 
Example 4
Source File: Horaires.java    From Android-Allocine-Api with Apache License 2.0 6 votes vote down vote up
public boolean isMoreThanToday() {
        try {
            String dateFormatted = getDate();

            Date now = new Date();
            now.setHours(0);
            now.setSeconds(0);
            now.setMinutes(0);

            SimpleDateFormat formater = new SimpleDateFormat("E dd MMMMM yyyy", Locale.FRANCE);
            Date date = formater.parse(dateFormatted);

            date.setHours(13);

            return date.equals(now) || date.after(now);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
}
 
Example 5
Source File: DateTimeViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
protected void putResults(Bundle results, String key) {
    Date res = new Date(day == null ? 0 : day);
    res.setHours(hour == null ? 0 : hour);
    res.setMinutes(minute == null ? 0 : minute);
    results.putLong(key, res.getTime());
}
 
Example 6
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkDateSetGetHour() {
    int COUNT = COUNT_FAST;
    Date dt = new Date();
    for (int i = 0; i < AVERAGE; i++) {
        start("Date", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHours(13);
            int val = dt.getHours();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 7
Source File: ClientIntervalBuilderDynamicDate.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected Date firstIntervalDate(DateIntervalType intervalType, Date minDate, ColumnGroup columnGroup) {
    Date intervalMinDate = new Date(minDate.getTime());
    if (YEAR.equals(intervalType)) {
        intervalMinDate.setMonth(0);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (QUARTER.equals(intervalType)) {
        int currentMonth = intervalMinDate.getMonth();
        int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex();
        int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1);
        intervalMinDate.setMonth(currentMonth - rest);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MONTH.equals(intervalType)) {
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType) || WEEK.equals(intervalType)) {
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (HOUR.equals(intervalType)) {
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MINUTE.equals(intervalType)) {
        intervalMinDate.setSeconds(0);
    }
    return intervalMinDate;
}
 
Example 8
Source File: DateTimeViewHolder.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
protected void putResults(Bundle results, String key) {
    Date res = new Date(day == null ? 0 : day);
    res.setHours(hour == null ? 0 : hour);
    res.setMinutes(minute == null ? 0 : minute);
    results.putLong(key, res.getTime());
}
 
Example 9
Source File: DisplayUtils.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static CharSequence getRelativeDateTimeString (
        Context c, long time, long minResolution, long transitionResolution, int flags
        ){
    
    CharSequence dateString = "";
    
    // in Future
    if (time > System.currentTimeMillis()){
        return DisplayUtils.unixTimeToHumanReadable(time);
    } 
    // < 60 seconds -> seconds ago
    else if ((System.currentTimeMillis() - time) < 60 * 1000) {
        return c.getString(R.string.file_list_seconds_ago);
    } else {
        // Workaround 2.x bug (see https://github.com/owncloud/android/issues/716)
        if (    Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && 
                (System.currentTimeMillis() - time) > 24 * 60 * 60 * 1000   ) {
            Date date = new Date(time);
            date.setHours(0);
            date.setMinutes(0);
            date.setSeconds(0);
            dateString = DateUtils.getRelativeDateTimeString(
                    c, date.getTime(), minResolution, transitionResolution, flags
            );
        } else {
            dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);
        }
    }
    
    return dateString.toString().split(",")[0];
}
 
Example 10
Source File: WindowProcessorTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatWithWeekdayExclusion() throws ParseException {
  Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago excluding weekdays");

  Date now = new Date();
  now.setHours(6); //avoid DST impacts if near Midnight
  List<Range<Long>> intervals = w.toIntervals(now.getTime());
  assertEquals(2, intervals.size());
}
 
Example 11
Source File: WindowProcessorTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatWithWeekendExclusion() {
  Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago excluding weekends");

  Date now = new Date();
  now.setHours(6); //avoid DST impacts if near Midnight
  List<Range<Long>> intervals = w.toIntervals(now.getTime());
  assertEquals(5, intervals.size());
}
 
Example 12
Source File: DateUtilTests.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTimeAtEndOfNow() {
    Date date = new Date();
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    String data = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    Assert.assertEquals(data, DateUtil.withTimeAtEndOfNow());
}
 
Example 13
Source File: WindowProcessorTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatWithConflictingExclusionInclusion() {
  Window w = WindowProcessor.process("30 minute window every 24 hours from 7 days ago including saturdays excluding weekends");

  Date now = new Date();
  now.setHours(6); //avoid DST impacts if near Midnight
  List<Range<Long>> intervals = w.toIntervals(now.getTime());
  assertEquals(0, intervals.size());
}
 
Example 14
Source File: DateUtilTests.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTimeAtEndOfNow() {
    Date date = new Date();
    date.setHours(23);
    date.setMinutes(59);
    date.setSeconds(59);
    String data = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    Assert.assertEquals(data, DateUtil.withTimeAtEndOfNow());
}
 
Example 15
Source File: AdminController.java    From MOOC with MIT License 4 votes vote down vote up
@RequestMapping(value="banip")//封禁ip
public void banip(HttpServletResponse resp,HttpSession session,String ip,String mark,String time) throws IOException{
	Date date = new Date();
	Ipset ip1 = ipsetBiz.selectip(ip);
	boolean isnull = false;
	if(ip1==null) {
		ip1=new Ipset();
		ip1.setIp(ip);
		isnull =true;
	}
	ip1.setIp(ip);
	ip1.setMark(mark);
	ip1.setType("1");
	if(time.equals("5m")) {
		if(date.getMinutes()>55) {
			date.setMinutes(date.getMinutes()-55);
			date.setHours(date.getHours()+1);
		}else {
		date.setMinutes(date.getMinutes()+5);
		}
		ip1.setBantime(date);
	}else if(time.equals("2h")) {
		date.setHours(date.getHours()+2);
		ip1.setBantime(date);
	}else if(time.equals("1d")) {
		date.setDate(date.getDate()+1);
		ip1.setBantime(date);
	}else if(time.equals("1m")) {
		date.setMonth(date.getMonth()+1);
		ip1.setBantime(date);
	}else if(time.equals("1y")) {
		date.setYear(date.getYear()+1);
		ip1.setBantime(date);
	}else if(time.equals("ever")) {
		date.setYear(date.getYear()+99);
		ip1.setBantime(date);
	}
	if(isnull) {
		ipsetBiz.insert(ip1);
	}else {
	ipsetBiz.updateByPrimaryKeySelective(ip1);
	}
	resp.setCharacterEncoding("utf-8");
	resp.getWriter().write("封禁成功!封禁至:"+date);
}
 
Example 16
Source File: AdminController.java    From MOOC with MIT License 4 votes vote down vote up
@RequestMapping(value="banip")//封禁ip
public void banip(HttpServletResponse resp,HttpSession session,String ip,String mark,String time) throws IOException{
	User loginUser = (User) session.getAttribute("loginUser");
	if (loginUser == null) {
		return ;
	}else if(!"admin".equals(loginUser.getMission())){
		//添加管理员的再次验证
		return ;
	}
	Date date = new Date();
	Ipset ip1 = ipsetBiz.selectip(ip);
	boolean isnull = false;
	if(ip1==null) {
		ip1=new Ipset();
		ip1.setIp(ip);
		isnull =true;
	}
	ip1.setIp(ip);
	ip1.setMark(mark);
	ip1.setType("1");
	switch (time) {
		case "5m":
			if (date.getMinutes() > 55) {
				date.setMinutes(date.getMinutes() - 55);
				date.setHours(date.getHours() + 1);
			} else {
				date.setMinutes(date.getMinutes() + 5);
			}
			ip1.setBantime(date);
			break;
		case "2h":
			date.setHours(date.getHours() + 2);
			ip1.setBantime(date);
			break;
		case "1d":
			date.setDate(date.getDate() + 1);
			ip1.setBantime(date);
			break;
		case "1m":
			date.setMonth(date.getMonth() + 1);
			ip1.setBantime(date);
			break;
		case "1y":
			date.setYear(date.getYear() + 1);
			ip1.setBantime(date);
			break;
		case "ever":
			date.setYear(date.getYear() + 99);
			ip1.setBantime(date);
			break;
	}
	if(isnull) {
		ipsetBiz.insert(ip1);
	}else {
	ipsetBiz.updateByPrimaryKeySelective(ip1);
	}
	resp.setCharacterEncoding("utf-8");
	resp.getWriter().write("封禁成功!封禁至:"+date);
}
 
Example 17
Source File: ClientIntervalBuilderDynamicDate.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
protected Date nextIntervalDate(Date intervalMinDate, DateIntervalType intervalType, int intervals) {
    Date intervalMaxDate = new Date(intervalMinDate.getTime());

    if (MILLENIUM.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 1000 * intervals);
    }
    else if (CENTURY.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 100 * intervals);
    }
    else if (DECADE.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 10 * intervals);
    }
    else if (YEAR.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() +  intervals);
    }
    else if (QUARTER.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + 3 * intervals);
    }
    else if (MONTH.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + intervals);
    }
    else if (WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + 7 * intervals);
    }
    else if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + intervals);
    }
    else if (HOUR.equals(intervalType)) {
        intervalMaxDate.setHours(intervalMinDate.getHours() + intervals);
    }
    else if (MINUTE.equals(intervalType)) {
        intervalMaxDate.setMinutes(intervalMinDate.getMinutes() + intervals);
    }
    else if (SECOND.equals(intervalType)) {
        intervalMaxDate.setSeconds(intervalMinDate.getSeconds() + intervals);
    }
    else {
        // Default to year to avoid infinite loops
        intervalMaxDate.setYear(intervalMinDate.getYear() + intervals);
    }
    return intervalMaxDate;
}
 
Example 18
Source File: DanaRS_Packet_General_Get_More_Information.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void handleMessage(byte[] data) {
    if (data.length < 15){
        failed = true;
        return;
    }
    DanaRPump pump = DanaRPump.getInstance();

    int dataIndex = DATA_START;
    int dataSize = 2;
    pump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize));

    dataIndex += dataSize;
    dataSize = 2;
    pump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;

    dataIndex += dataSize;
    dataSize = 1;
    pump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01;

    dataIndex += dataSize;
    dataSize = 2;
    pump.extendedBolusRemainingMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize));

    dataIndex += dataSize;
    dataSize = 2;
    double remainRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;

    Date lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
    dataIndex += dataSize;
    dataSize = 1;
    lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));

    dataIndex += dataSize;
    dataSize = 1;
    lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));

    dataIndex += dataSize;
    dataSize = 2;
    pump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize));
    // On DanaRS DailyUnits can't be more than 160
    if(pump.dailyTotalUnits > 160)
        failed = true;
    if (L.isEnabled(L.PUMPCOMM)) {
        log.debug("Daily total units: " + pump.dailyTotalUnits + " U");
        log.debug("Is extended in progress: " + pump.isExtendedInProgress);
        log.debug("Extended bolus remaining minutes: " + pump.extendedBolusRemainingMinutes);
        log.debug("Last bolus time: " + lastBolusTime.toLocaleString());
        log.debug("Last bolus amount: " + pump.lastBolusAmount);
    }
}
 
Example 19
Source File: DanaRS_Packet_Bolus_Get_Step_Bolus_Information.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void handleMessage(byte[] data) {
    DanaRPump pump = DanaRPump.getInstance();

    int dataIndex = DATA_START;
    int dataSize = 1;
    int error = byteArrayToInt(getBytes(data, dataIndex, dataSize));

    dataIndex += dataSize;
    dataSize = 1;
    int bolusType = byteArrayToInt(getBytes(data, dataIndex, dataSize));

    dataIndex += dataSize;
    dataSize = 2;
    pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;

    Date lbt = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
    dataIndex += dataSize;
    dataSize = 1;
    lbt.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));

    dataIndex += dataSize;
    dataSize = 1;
    lbt.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));

    pump.lastBolusTime = lbt.getTime();

    dataIndex += dataSize;
    dataSize = 2;
    pump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;

    dataIndex += dataSize;
    dataSize = 2;
    pump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;

    dataIndex += dataSize;
    dataSize = 1;
    pump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
    if (error != 0)
        failed = true;
    if (L.isEnabled(L.PUMPCOMM)) {
        log.debug("Result: " + error);
        log.debug("BolusType: " + bolusType);
        log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U");
        log.debug("Last bolus time: " + DateUtil.dateAndTimeFullString(pump.lastBolusTime));
        log.debug("Last bolus amount: " + pump.lastBolusAmount);
        log.debug("Max bolus: " + pump.maxBolus + " U");
        log.debug("Bolus step: " + pump.bolusStep + " U");
    }
}
 
Example 20
Source File: HotelOrderCreateTester.java    From eLong-OpenAPI-JAVA-demo with Apache License 2.0 4 votes vote down vote up
@Override
public CreateOrderCondition getConditon() {
	CreateOrderCondition condition = new CreateOrderCondition();
		Date date = new Date();
		date = util.Tool.addDate(date, 1);
		Date date2 = util.Tool.addDate(date, 1);
		Date date3 = util.Tool.addDate(date, 0);
		date3.setHours(15);
		date3.setMinutes(0);
		date3.setSeconds(0);
		Date date4 = util.Tool.addDate(date, 0);
		date4.setHours(17);
		date4.setMinutes(0);
		date4.setSeconds(0);
		
		condition.setHotelId("10101129");
		condition.setRoomTypeId("0010");
		condition.setRatePlanId(145742);
		condition.setTotalPrice(new BigDecimal(600));
		condition.setAffiliateConfirmationId("my-order-id-2");
		
		condition.setArrivalDate(date);
		condition.setConfirmationType(elong.EnumConfirmationType.NotAllowedConfirm);
		condition.setContact(getContact());
		condition.setCreditCard(getCreditCard());
		condition.setCurrencyCode(elong.EnumCurrencyCode.HKD);
		condition.setCustomerIPAddress("211.151.230.21");
		condition.setCustomerType(elong.EnumGuestTypeCode.OtherForeign);
		condition.setDepartureDate(date2);
		condition.setEarliestArrivalTime(date3);
		condition.setExtendInfo(null);			
		condition.setInvoice(null);
		condition.setIsForceGuarantee(false);
		condition.setIsGuaranteeOrCharged(false);
		condition.setIsNeedInvoice(false);
		condition.setLatestArrivalTime(date4);
		condition.setNightlyRates(null);
		condition.setNoteToElong("");
		condition.setNoteToHotel(null);
		condition.setNumberOfCustomers(1);
		condition.setNumberOfRooms(1);
		condition.setOrderRooms( getRooms() );
		condition.setPaymentType(elong.EnumPaymentType.SelfPay);
		condition.setSupplierCardNo(null);
		
		
	
	return condition;
}