roll ( )源码实例Demo

java.util.Calendar#roll ( )源码实例Demo

下面列出了java.util.Calendar#roll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: activiti6-boot2   文件: TaskQueryTest.java
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueDate() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Set due-date on task
  Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueDate(dueDate).count());

  Calendar otherDate = Calendar.getInstance();
  otherDate.add(Calendar.YEAR, 1);
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueDate(otherDate.getTime()).count());

  Calendar priorDate = Calendar.getInstance();
  priorDate.setTime(dueDate);
  priorDate.roll(Calendar.YEAR, -1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueAfter(priorDate.getTime()).count());

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(otherDate.getTime()).count());
}
 
private void initSettings() {
  today = MaterialDatePicker.todayInUtcMilliseconds();
  Calendar calendar = getClearedUtc();
  calendar.setTimeInMillis(today);
  calendar.roll(Calendar.MONTH, 1);
  nextMonth = calendar.getTimeInMillis();

  calendar.setTimeInMillis(today);
  calendar.set(Calendar.MONTH, Calendar.JANUARY);
  janThisYear = calendar.getTimeInMillis();
  calendar.setTimeInMillis(today);
  calendar.set(Calendar.MONTH, Calendar.DECEMBER);
  decThisYear = calendar.getTimeInMillis();

  calendar.setTimeInMillis(today);
  calendar.roll(Calendar.YEAR, 1);
  oneYearForward = calendar.getTimeInMillis();

  todayPair = new Pair<>(today, today);
  nextMonthPair = new Pair<>(nextMonth, nextMonth);
}
 
源代码3 项目: oval   文件: PastTest.java
public void testPast() {
   final PastCheck isInPast = new PastCheck();
   super.testCheck(isInPast);
   assertTrue(isInPast.isSatisfied(null, null, null, null));

   final Calendar cal = Calendar.getInstance();
   cal.roll(Calendar.YEAR, -1);
   assertTrue(isInPast.isSatisfied(null, cal, null, null));
   assertTrue(isInPast.isSatisfied(null, cal.getTime(), null, null));
   assertTrue(isInPast.isSatisfied(null, DateFormat.getDateTimeInstance().format(cal.getTime()), null, null));

   cal.roll(Calendar.YEAR, 2);
   assertFalse(isInPast.isSatisfied(null, cal, null, null));
   assertFalse(isInPast.isSatisfied(null, cal.getTime(), null, null));
   assertFalse(isInPast.isSatisfied(null, DateFormat.getDateTimeInstance().format(cal.getTime()), null, null));

   assertFalse(isInPast.isSatisfied(null, "bla", null, null));
}
 
源代码4 项目: sql-layer   文件: YamlTesterDateTimeTest.java
@Test
public void testDateTimeTag() {
    Calendar cal = getCalendar();
    String time = formatDateTime(cal);
    testdt(time);
    cal = getCalendar();
    cal.roll(Calendar.SECOND, -30);
    time = formatDateTime(cal);
    testdt(time);
    cal = getCalendar();
    cal.roll(Calendar.SECOND, 30);
    time = formatDateTime(cal);
    testdt(time);
}
 
源代码5 项目: uyuni   文件: SystemOverviewActionTest.java
public void testSystemActive() throws Exception {
    Calendar pcal = Calendar.getInstance();
    pcal.setTime(new Timestamp(System.currentTimeMillis()));
    pcal.roll(Calendar.MINUTE, -5);

    s.getServerInfo().setCheckin(pcal.getTime());
    TestUtils.saveAndFlush(s);
    actionPerform();
    assertEquals(request.getAttribute("systemInactive"), Boolean.FALSE);
}
 
源代码6 项目: uyuni   文件: ChannelFactoryTest.java
public static Channel createTestChannel(Org org, ChannelArch arch, ChannelFamily cfam) throws Exception {
    String label = "channellabel" + TestUtils.randomString().toLowerCase();
    String basedir = "TestChannel basedir";
    String name = "ChannelName" + TestUtils.randomString();
    String summary = "TestChannel summary";
    String description = "TestChannel description";
    Date lastmodified = new Date();
    Date created = new Date();
    Date modified = new Date();
    String gpgurl = "https://gpg.url";
    String gpgid = "B3BCE11D";
    String gpgfp = "AAAA BBBB CCCC DDDD EEEE FFFF 7777 8888 9999 0000";
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, true);
    Date endoflife = new Date(System.currentTimeMillis() + Integer.MAX_VALUE);

    Channel c = new Channel();
    c.setOrg(org);
    c.setLabel(label);
    c.setBaseDir(basedir);
    c.setName(name);
    c.setSummary(summary);
    c.setDescription(description);
    c.setLastModified(lastmodified);
    c.setCreated(created);
    c.setModified(modified);
    c.setGPGKeyUrl(gpgurl);
    c.setGPGKeyId(gpgid);
    c.setGPGKeyFp(gpgfp);
    c.setEndOfLife(endoflife);
    c.setChannelArch(arch);
    c.setChannelFamily(cfam);
    ChannelFactory.save(c);
    return c;
}
 
源代码7 项目: classchecks   文件: DateUtil.java
public static Date getLastDayOfMonth(Integer year, Integer month) {
	Calendar calendar = Calendar.getInstance();
	if (year == null) {
		year = calendar.get(Calendar.YEAR);
	}
	if (month == null) {
		month = calendar.get(Calendar.MONTH);
	}
	calendar.set(year, month, 1);
	calendar.roll(Calendar.DATE, -1);
	return calendar.getTime();
}
 
源代码8 项目: mpxj   文件: ProjectCalendar.java
/**
 * This method calculates the absolute number of days between two dates.
 * Note that where two date objects are provided that fall on the same
 * day, this method will return one not zero. Note also that this method
 * assumes that the dates are passed in the correct order, i.e.
 * startDate < endDate.
 *
 * @param startDate Start date
 * @param endDate End date
 * @return number of days in the date range
 */
private int getDaysInRange(Date startDate, Date endDate)
{
   int result;
   Calendar cal = DateHelper.popCalendar(endDate);
   int endDateYear = cal.get(Calendar.YEAR);
   int endDateDayOfYear = cal.get(Calendar.DAY_OF_YEAR);

   cal.setTime(startDate);

   if (endDateYear == cal.get(Calendar.YEAR))
   {
      result = (endDateDayOfYear - cal.get(Calendar.DAY_OF_YEAR)) + 1;
   }
   else
   {
      result = 0;
      do
      {
         result += (cal.getActualMaximum(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR)) + 1;
         cal.roll(Calendar.YEAR, 1);
         cal.set(Calendar.DAY_OF_YEAR, 1);
      }
      while (cal.get(Calendar.YEAR) < endDateYear);
      result += endDateDayOfYear;
   }
   DateHelper.pushCalendar(cal);

   return result;
}
 
源代码9 项目: Easer   文件: Utils.java
static void scheduleAlarmEveryday(AlarmManager alarmManager, PendingIntent pendingIntent) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0); // 00:00
    calendar.roll(Calendar.DAY_OF_YEAR, 1); // "Tomorrow" (with extra care from the next code block)
    if (calendar.get(Calendar.DAY_OF_YEAR) == 0) // First day of year, but year is not rolled
        calendar.roll(Calendar.YEAR, 1);
    // calendar == Tomorrow 00:00
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pendingIntent);
}
 
源代码10 项目: JavaExercises   文件: TestDateAndCalendar.java
public static void main(String[] args) {

        System.out.println("Testing Date\n");
        
        Date today = new Date();
        System.out.println(String.format("%tc", today));
        System.out.println(String.format("%tr", today));
        System.out.println(String.format("%tA %tB %td", today, today, today));
        System.out.println(String.format("%tA %<tB %<td", today));

        System.out.println("\nTesting Calendar\n");
        
        Calendar cal = Calendar.getInstance();
        cal.set(2016, 6, 10, 13, 12);
        long day1 = cal.getTimeInMillis();
        day1 += 1000 * 60 * 60;
        cal.setTimeInMillis(day1);
        System.out.println("new hour "+ cal.get(cal.HOUR_OF_DAY));
        
        cal.add(cal.DATE, 35) ;
        System.out.println("add 35 days " + cal.getTime());

        cal.roll(cal.DATE, 35);
        System.out.println("roll 35 days" + cal.getTime());
        
        cal.set(cal.DATE, 1);
        System.out.println("set to 1 " + cal.getTime());

    }
 
源代码11 项目: CloudReader   文件: TimeUtil.java
/**
 * 获取当月的 天数
 */
public static int getCurrentMonthDay() {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    return a.get(Calendar.DATE);
}
 
源代码12 项目: fenixedu-academic   文件: UIFenixCalendar.java
private static void setToFirstDayOfNextMonth(Calendar date) {
    if (date.get(Calendar.MONTH) < 11) {
        date.roll(Calendar.MONTH, true);
    } else {
        date.roll(Calendar.MONTH, true);
        date.roll(Calendar.YEAR, true);
    }
    date.set(Calendar.DAY_OF_MONTH, 1);
}
 
源代码13 项目: MicroCommunity   文件: DateUtil.java
public static int getCurrentMonthDay() {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.DATE, 1);
    a.roll(Calendar.DATE, -1);
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}
 
源代码14 项目: ONE-Unofficial   文件: TimeUtil.java
/**
 * 将指定日期进行偏移,获取偏移后的日期,eg:2015-09-06
 *
 * @param date   要偏移的日期,需是"2015-09-06"格式
 * @param offset 偏移的值,可正可负
 * @return
 */
public static String getPreviousDate(String date, int offset) {
    try {
        Date d = format_date.parse(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        calendar.roll(Calendar.DAY_OF_MONTH, -offset + 1);
        return format_date.format(calendar.getTime());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}
 
源代码15 项目: FoxBPM   文件: DateCalUtils.java
/**
 * 得到指定月的天数
 * */
public static int getMonthLastDay(int year, int month)
{
	Calendar a = Calendar.getInstance();
	a.set(Calendar.YEAR, year);
	a.set(Calendar.MONTH, month - 1);
	a.set(Calendar.DATE, 1);//把日期设置为当月第一天
	a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
	int maxDate = a.get(Calendar.DATE);
	return maxDate;
}
 
源代码16 项目: openjdk-jdk9   文件: Bug8152077.java
private static void testRoll(int amount, int[] params, int[] sequence, int startIndex) {
    int year = params[0];
    int month = params[1];
    int dayOfMonth = params[2];
    int hourOfDay = sequence[startIndex];
    Calendar cal = new GregorianCalendar(year, month, dayOfMonth,
                                         hourOfDay, 0, 0);
    int ampm = cal.get(AM_PM);

    int length = sequence.length;
    int count = length * 2;
    int field = (length > 12) ? HOUR_OF_DAY : HOUR;

    System.out.printf("roll(%s, %2d) starting from %s%n",
                      (field == HOUR) ? "HOUR" : "HOUR_OF_DAY", amount, cal.getTime());
    for (int i = 0; i < count; i++) {
        int index = (amount > 0) ? (startIndex + i + 1) % length
                                 : Math.floorMod(startIndex - i - 1, length);
        int expected = sequence[index];
        if (field == HOUR) {
            expected %= 12;
        }
        cal.roll(field, amount);
        int value = cal.get(field);
        if (value != expected) {
            System.out.println("Unexpected field value: got=" + value
                                + ", expected=" + expected);
            errors++;
        }
        if (cal.get(DAY_OF_MONTH) != dayOfMonth) {
            System.out.println("DAY_OF_MONTH changed: " + dayOfMonth
                                + " to " + cal.get(DAY_OF_MONTH));
        }
        if (field == HOUR && cal.get(AM_PM) != ampm) {
            System.out.println("AM_PM changed: " + ampm + " to " + cal.get(AM_PM));
            errors++;
        }
    }
}
 
源代码17 项目: spacewalk   文件: ChannelFactoryTest.java
public static Channel createTestChannel(Org org, ChannelFamily cfam) throws Exception {
    String label = "channellabel" + TestUtils.randomString().toLowerCase();
    String basedir = "TestChannel basedir";
    String name = "ChannelName" + TestUtils.randomString();
    String summary = "TestChannel summary";
    String description = "TestChannel description";
    Date lastmodified = new Date();
    Date created = new Date();
    Date modified = new Date();
    String gpgurl = "https://gpg.url";
    String gpgid = "B3BCE11D";
    String gpgfp = "AAAA BBBB CCCC DDDD EEEE FFFF 7777 8888 9999 0000";
    Calendar cal = Calendar.getInstance();
    cal.roll(Calendar.DATE, true);
    Date endoflife = new Date(System.currentTimeMillis() + Integer.MAX_VALUE);

    Long testid = new Long(500);
    String query = "ChannelArch.findById";
    ChannelArch arch = (ChannelArch) TestUtils.lookupFromCacheById(testid, query);
    Channel c = new Channel();
    c.setOrg(org);
    c.setLabel(label);
    c.setBaseDir(basedir);
    c.setName(name);
    c.setSummary(summary);
    c.setDescription(description);
    c.setLastModified(lastmodified);
    c.setCreated(created);
    c.setModified(modified);
    c.setGPGKeyUrl(gpgurl);
    c.setGPGKeyId(gpgid);
    c.setGPGKeyFp(gpgfp);
    c.setEndOfLife(endoflife);
    c.setChannelArch(arch);
    c.setChannelFamily(cfam);
    ChannelFactory.save(c);
    return c;
}
 
源代码18 项目: quickhybrid-android   文件: DateUtil.java
/**
 * 得到指定月的天数
 */
public static int getMonthLastDay(int year, int month) {
    Calendar a = Calendar.getInstance();
    a.set(Calendar.YEAR, year);
    a.set(Calendar.MONTH, month - 1);
    a.set(Calendar.DATE, 1);// 把日期设置为当月第一天
    a.roll(Calendar.DATE, -1);// 日期回滚一天,也就是最后一天
    int maxDate = a.get(Calendar.DATE);
    return maxDate;
}
 
源代码19 项目: Linphone4Android   文件: HistoryListFragment.java
private boolean isYesterday(Calendar cal) {
	Calendar yesterday = Calendar.getInstance();
	yesterday.roll(Calendar.DAY_OF_MONTH, -1);
	return isSameDay(cal, yesterday);
}
 
源代码20 项目: AsuraFramework   文件: DateUtil.java
/**
 * 
 * 获取指定日期所在月的最后一天
 *
 * @author zhangshaobin
 * @created 2012-11-5 下午7:04:10
 *
 * @param date
 * @return	以"年年年年-月月-日日"格式返回当指定月最后一天的日期
 */
public static String getLastDayOfMonth(final Date date) {
	final Calendar ca = Calendar.getInstance();
	ca.setTime(date);
	ca.set(Calendar.DAY_OF_MONTH, 1);
	ca.roll(Calendar.DAY_OF_MONTH, -1);
	//		return dateFormat.format(ca.getTime());
	return getDateFormat().format(ca.getTime());
}