APISonar


java.util.Calendar.DATE

> java > util > Calendar > DATE
java APIs util APIs Calendar APIs DATE APIs

Example 1
public static Date addDay(Date date, int n) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, n);
        return cal.getTime();

    }
Example 2
private static Date toDays(@Nullable String s) {
    if (s != null) {
      int days = Integer.valueOf(s);
      Date date = org.apache.commons.lang.time.DateUtils.truncate(new Date(), Calendar.DATE);
      date = org.apache.commons.lang.time.DateUtils.addDays(date, -days);
      return date;
    }
    return null;
  }
Example 3
public static Date getYesterday() {
        Date now = new Date();

        Calendar yesterdayCal = Calendar.getInstance();
        yesterdayCal.setTime(now);
        yesterdayCal.add(Calendar.DATE, -1);

        String yesterdayStr = getDay(yesterdayCal.getTime());
        return getDay(yesterdayStr);
    }
Example 4
public static Date endOfDay(Date d) {
		return DateUtils.addSeconds(
				DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), 1), -1);
	}
Example 5
protected Date determineRemovalTime(Date initTime, Integer timeToLive) {
    Calendar removalTime = Calendar.getInstance();
    removalTime.setTime(initTime);
    removalTime.add(Calendar.DATE, timeToLive);

    return removalTime.getTime();
  }
Example 6
private void refreshButtons() {
        final Calendar c = getFirstVisibleDate();
        for (int i = 0; i < 42; i++) {
            final JButton b = this.buttons[i];
            b.setText(Integer.toString(c.get(Calendar.DATE)));
            b.setBackground(getButtonColor(c));
            c.add(Calendar.DATE, 1);
        }
    }
Example 7
public void test() {
        Assert.assertTrue(DateUtils.isSameMinute(new Date(), new Date()));
        Assert.assertTrue(DateUtils.isSameHour(new Date(), new Date()));
        Assert.assertTrue(DateUtils.isSameDay(new Date(), new Date()));

        Calendar calendar1 = Calendar.getInstance();
        calendar1.add(Calendar.MINUTE, 1);
        Assert.assertFalse(DateUtils.isSameMinute(new Date(), calendar1.getTime()));

        calendar1.add(Calendar.HOUR_OF_DAY, 1);
        Assert.assertFalse(DateUtils.isSameHour(new Date(), calendar1.getTime()));

        calendar1.add(Calendar.DATE, 1);
        Assert.assertFalse(DateUtils.isSameDay(new Date(), calendar1.getTime()));
    }
Example 8
public void testTruncateDate() throws Exception {
        final int calendarField = Calendar.DATE;
        Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
        baseTruncateTest(targetDateDate, lastTruncateDate, calendarField);
    }
Example 9
public Booking(long bookingTypeId, long customerId) {
		Calendar today = GregorianCalendar.getInstance();

		Calendar weekFromToday = (Calendar)today.clone();

		weekFromToday.add(Calendar.DATE, 7);

		_bookingTypeId = bookingTypeId;
		_customerId = customerId;
		_startDate = new Date(today.getTimeInMillis());
		_finishDate = new Date(weekFromToday.getTimeInMillis());
	}
Example 10
private Double getWithdrawServFee(Long userId, Double transAmt) {
        Date beginDate = DateUtils.truncate(DateUtils.setDays(new Date(), 1), Calendar.DATE);
        Date endDate = DateUtils.addMonths(beginDate, 1);
        int count = withdrawComponent.countWithdrawQty(userId, beginDate, endDate);
        if (count > 3) {
            Double servFee = CalculateUtils.mul(transAmt, 0.01);
            return (CalculateUtils.lt(servFee, 2.00) ? servFee : 2.00);
        } else {
            return 0.00;
        }
    }
Example 11
public void dateToJson() throws IOException {
        GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        calendar.add(Calendar.DATE, 10000);
        java.util.Date date = calendar.getTime();

        JsonNode converted = parse(converter.fromConnectData(TOPIC, Date.SCHEMA, date));
        validateEnvelope(converted);
        assertEquals(parse("{ \"type\": \"int32\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Date\", \"version\": 1 }"),
                converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
        JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
        assertTrue(payload.isInt());
        assertEquals(10000, payload.intValue());
    }
Example 12
public static void main(String[] args) throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, 1);
    Date tomorrow = cal.getTime();

    //read the key as a base 64 url-safe encoded string, then convert to byte array
    final String keyPath = "/path/to/key";
    String base64String = new String(Files.readAllBytes(Paths.get(keyPath)));
    byte[] keyBytes = Base64.getUrlDecoder().decode(base64String);

    String result = signUrl("http://example.com/", keyBytes, "YOUR-KEY-NAME", tomorrow);
    System.out.println(result);
  }
Example 13
public void testGetDifferenceDays() {
        Date now = new Date();
        assertTrue(QuotaAlertManagerImpl.getDifferenceDays(now, now) == 0L);
        Calendar c = Calendar.getInstance();
        c.setTimeZone(TimeZone.getTimeZone("UTC"));
        Calendar c2 = (Calendar)c.clone();
        c2.add(Calendar.DATE, 1);
        assertEquals(1L, QuotaAlertManagerImpl.getDifferenceDays(c.getTime(), c2.getTime()));
    }
Example 14
private Date getGraceDate() {
		// get the gracetime config param in days.
		int gracetime = serverConfigurationService.getInt(
				"site.soft.deletion.gracetime", GRACETIME_DEFAULT);

		// get calendar for gracetime
		Calendar grace = Calendar.getInstance();
		grace.add(Calendar.DATE, -gracetime);
		Date graceDate = grace.getTime();
		log.debug("Grace set to: " + graceDate);
		return graceDate;
	}
Example 15
public void reportUsage() {
		if (config.isUsageReportEnabled()) {
			doRandomDelay();
			GoogleAnalytic googleAnalytic = new GoogleAnalytic(ControllerConstants.GOOGLE_ANALYTICS_APP_NAME,
					config.getVersion(), ControllerConstants.GOOGLE_ANALYTICS_TRACKING_ID);
			MeasureProtocolRequest measureProtocolRequest = googleAnalytic.getMeasureProtocolRequest();
			measureProtocolRequest.setEventCategory("usage");
			measureProtocolRequest.setEventAction("executions");
			String currentAddress = NetworkUtils.getLocalHostAddress();
			Date yesterday = DateUtils.addDays(new Date(), -1);
			Date start = DateUtils.truncate(yesterday, Calendar.DATE);
			Date end = DateUtils.addMilliseconds(DateUtils.ceiling(yesterday, Calendar.DATE), -1);
			googleAnalytic.sendStaticDataToUA(currentAddress, String.valueOf(getUsage(start, end)));
		}
	}
Example 16
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.date);

        final DatePicker picker = (DatePicker) findViewById(R.id.picker);
        picker.init(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), new DatePickerListener());
    }
Example 17
public void onCalendarClicked() {
        CustomDatePicker newFragment = new CustomDatePicker();
        newFragment.setSelectedDay(date.get(Calendar.MONTH), date.get(Calendar.DATE));
        newFragment.setCallback(OnThisDayFragment.this);
        newFragment.show(requireFragmentManager(), "date picker");
    }
Example 18
private static Calendar getEndingDateAccordingToStartingDate(double date, Calendar startingDate) {
        Calendar endingDate = getDate(date);
        endingDate.setTime(DateUtil.getJavaDate(date, false));
        if (isLastDayOfMonth(endingDate)) {
            if (startingDate.get(Calendar.DATE) < 30) {
                endingDate = getFirstDayOfNextMonth(endingDate);
            }
        }
        return endingDate;
    }
Example 19
public void testInputHasMoreCharacters() {
        final FastDateParser parser = new FastDateParser("MM/dd", TimeZone.getDefault(), Locale.getDefault());
        final ParsePosition parsePosition = new ParsePosition(0);
        final Date date = parser.parse("3/23/61", parsePosition);
        Assert.assertEquals(4, parsePosition.getIndex());

        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Assert.assertEquals(2, calendar.get(Calendar.MONTH));
        Assert.assertEquals(23, calendar.get(Calendar.DATE));       
    }
Example 20
private static FromToPair parseDates(String fromDate, String toDate, TimeZone timeZone)
            throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        simpleDateFormat.setTimeZone(timeZone);
        Date from = simpleDateFormat.parse(fromDate);
        Date to = simpleDateFormat.parse(toDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(to);
        cal.add(Calendar.DATE, 1);
        to = cal.getTime();
        return ImmutableFromToPair.builder()
                .from(from)
                .to(to)
                .build();
    }
Example 21
public synchronized void nextDateDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);
        dateChange = 1;
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + dateChange);
        updateCalendar(canvas);
    }
Example 22
public void testRoundDate() throws Exception {
        final int calendarField = Calendar.DATE;
        Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
        Date minDate, maxDate;

        roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000");
        roundedDownDate = targetDateDate;
        lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 11:59:59.999");
        baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate,  calendarField);
        
        //round to January 1
        minDate = dateTimeParser.parse("December 31, 2007 12:00:00.000");
        maxDate = dateTimeParser.parse("January 1, 2008 11:59:59.999");
        roundToJanuaryFirst(minDate, maxDate, calendarField);
    }
Example 23
public void setStartDate(Date startDate) {
       if (startDate != null) {
           // fix up the date to shift to be beginning or end of the day (drop any time component)
           startDate = DateUtils.truncate(startDate, Calendar.DATE);
       }
       this.startDate = startDate;
   }
Example 24
public static List<String> getRecentDates(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		List<String> list = new ArrayList<String>();
		Calendar c = Calendar.getInstance();  
		for(int i = 0; i < 5; i++){
			c.add(Calendar.DATE,-1);
			list.add(sdf.format(c.getTime()));
		}
		return list;
	}
Example 25
public void customizeDateFormatNone() throws Exception {
		this.factory.afterPropertiesSet();
		Gson gson = this.factory.getObject();
		DateBean bean = new DateBean();
		Calendar cal = Calendar.getInstance();
		cal.clear();
		cal.set(Calendar.YEAR, 2014);
		cal.set(Calendar.MONTH, Calendar.JANUARY);
		cal.set(Calendar.DATE, 1);
		Date date = cal.getTime();
		bean.setDate(date);
		String result = gson.toJson(bean);
		assertThat(result.startsWith("{\"date\":\"Jan 1, 2014")).isTrue();
		assertThat(result.endsWith("12:00:00 AM\"}")).isTrue();
	}