当前位置: 首页>>代码示例>>Java>>正文


Java DateTime类代码示例

本文整理汇总了Java中org.dmfs.rfc5545.DateTime的典型用法代码示例。如果您正苦于以下问题:Java DateTime类的具体用法?Java DateTime怎么用?Java DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DateTime类属于org.dmfs.rfc5545包,在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWithDueDateAndOriginalTime

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void testWithDueDateAndOriginalTime() throws Exception
{
    DateTime due = DateTime.now();
    DateTime original = due.addDuration(Duration.parse("P2DT2H"));
    assertThat(new InstanceTestData(absent(), new Present<>(due), new Present<>(original), 5),
            builds(
                    withValuesOnly(
                            withNullValue(TaskContract.Instances.INSTANCE_START),
                            withNullValue(TaskContract.Instances.INSTANCE_START_SORTING),
                            containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.swapTimeZone(TimeZone.getDefault()).getInstance()),
                            withNullValue(TaskContract.Instances.INSTANCE_DURATION),
                            containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()),
                            containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5),
                            withNullValue(TaskContract.Instances.DTSTART),
                            containing(TaskContract.Instances.DUE, due.getTimestamp()),
                            containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()),
                            withNullValue(TaskContract.Instances.DURATION),
                            withNullValue(TaskContract.Instances.RRULE),
                            withNullValue(TaskContract.Instances.RDATE),
                            withNullValue(TaskContract.Instances.EXDATE)
                    )
            ));
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:26,代码来源:InstanceTestDataTest.java

示例2: peekDateTime

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
/**
 * Peek at the next instance to be returned by {@link #nextDateTime()} without actually iterating it. Calling this method (even multiple times) won't affect
 * the instances returned by {@link #nextDateTime()}.
 *
 * @return the upcoming instance or <code>null</code> if there are no more instances.
 */
public DateTime peekDateTime()
{
    if (mNextInstance == Long.MIN_VALUE)
    {
        throw new ArrayIndexOutOfBoundsException("No more instances to iterate.");
    }

    long nextInstance = mNextInstance;
    if (mAllDay)
    {
        return mNextDateTime = new DateTime(mCalendarMetrics, Instance.year(nextInstance),
                Instance.month(nextInstance), Instance.dayOfMonth(nextInstance));
    }
    else
    {
        return mNextDateTime = new DateTime(mCalendarMetrics, mTimeZone, Instance.year(nextInstance),
                Instance.month(nextInstance),
                Instance.dayOfMonth(nextInstance), Instance.hour(nextInstance), Instance.minute(nextInstance),
                Instance.second(nextInstance));
    }
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:28,代码来源:RecurrenceRuleIterator.java

示例3: test_whenHasTimeZoneNotAllDay_setsValuesAccordingly_andNullsOtherTimeRelatedValues

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void test_whenHasTimeZoneNotAllDay_setsValuesAccordingly_andNullsOtherTimeRelatedValues()
{
    DateTime due = DateTime.now().shiftTimeZone(TimeZone.getTimeZone("GMT+4"));

    assertThat(new DueData(due),
            builds(
                    withValuesOnly(
                            containing(Tasks.DUE, due.getTimestamp()),
                            containing(Tasks.TZ, "GMT+04:00"),
                            containing(Tasks.IS_ALLDAY, 0),

                            withNullValue(Tasks.DTSTART),

                            withNullValue(Tasks.DURATION),

                            withNullValue(Tasks.RDATE),
                            withNullValue(Tasks.RRULE),
                            withNullValue(Tasks.EXDATE)
                    )));
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:22,代码来源:DueDataTest.java

示例4: test_whenOnlyStartIsProvided_setsItAndNullsDueAndDuration

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void test_whenOnlyStartIsProvided_setsItAndNullsDueAndDuration()
{
    DateTime start = DateTime.now();

    assertThat(new TimeData(start),
            builds(
                    withValuesOnly(
                            containing(Tasks.DTSTART, start.getTimestamp()),
                            containing(Tasks.TZ, "UTC"),
                            containing(Tasks.IS_ALLDAY, 0),

                            withNullValue(Tasks.DUE),

                            withNullValue(Tasks.DURATION),

                            withNullValue(Tasks.RDATE),
                            withNullValue(Tasks.RRULE),
                            withNullValue(Tasks.EXDATE)
                    )));
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:22,代码来源:TimeDataTest.java

示例5: getFrom

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Override
public DateTime getFrom(ContentValues values)
{
	Long timestamp = values.getAsLong(mTimestampField);
	if (timestamp == null)
	{
		// if the time stamp is null we return null
		return null;
	}
	// create a new Time for the given time zone, falling back to UTC if none is given
	String timezone = mTzField == null ? null : values.getAsString(mTzField);
	DateTime value = new DateTime(timezone == null ? DateTime.UTC : TimeZone.getTimeZone(timezone), timestamp);

	// cache mAlldayField locally
	String allDayField = mAllDayField;

	// set the allday flag appropriately
	Integer allDayInt = allDayField == null ? null : values.getAsInteger(allDayField);

	if ((allDayInt != null && allDayInt != 0) || (allDayField == null && mAllDayDefault))
	{
		value = value.toAllDay();
	}

	return value;
}
 
开发者ID:dmfs,项目名称:opentasks-provider,代码行数:27,代码来源:DateTimeFieldAdapter.java

示例6: test_whenNoTimeZoneNotAllDay_setsValuesAccordingly_andNullsOtherTimeRelatedValues

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void test_whenNoTimeZoneNotAllDay_setsValuesAccordingly_andNullsOtherTimeRelatedValues()
{
    DateTime due = DateTime.now();

    assertThat(new DueData(due),
            builds(
                    withValuesOnly(
                            containing(Tasks.DUE, due.getTimestamp()),
                            containing(Tasks.TZ, "UTC"),
                            containing(Tasks.IS_ALLDAY, 0),

                            withNullValue(Tasks.DTSTART),

                            withNullValue(Tasks.DURATION),

                            withNullValue(Tasks.RDATE),
                            withNullValue(Tasks.RRULE),
                            withNullValue(Tasks.EXDATE)
                    )));
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:22,代码来源:DueDataTest.java

示例7: testInstance

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
public void testInstance(DateTime instance)
{
    if (printInstances)
    {
        System.out.println(instance.toString());
    }
    assertMonth(instance);
    assertWeekday(instance);
    assertUntil(instance);
    assertWeek(instance);
    assertMonthday(instance);
    assertHours(instance);
    assertMinutes(instance);
    assertSeconds(instance);
    assertAllDay(instance);
    assertTimeZone(instance);
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:18,代码来源:TestRule.java

示例8: testToAllDay

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
public void testToAllDay()
{
	DateTime calClone = cal.toAllDay();
	assertEquals(0, calClone.getHours());
	assertEquals(0, calClone.getMinutes());
	assertEquals(0, calClone.getSeconds());

	// date must stay the same
	assertEquals(cal.getYear(), calClone.getYear());
	assertEquals(cal.getMonth(), calClone.getMonth());
	assertEquals(cal.getMonth(), calClone.getMonth());

	assertTrue(calClone.isFloating());
	assertTrue(calClone.isAllDay());

	assertEquals(TimeZone.getTimeZone("UTC"), calClone.getTimeZone());

}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:19,代码来源:TestDate.java

示例9: expandRule

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
private List<DateTime> expandRule(TestRule rule)
{
	try
	{
		RecurrenceRule r = new RecurrenceRule(rule.rule, rule.mode);
		RecurrenceRuleIterator it = r.iterator(rule.start);
		List<DateTime> instances = new ArrayList<DateTime>(1000);
		int count = 0;
		while (it.hasNext())
		{
			DateTime instance = it.nextDateTime();
			instances.add(instance);
			count++;
			if (count == 10/* RecurrenceIteratorTest.MAX_ITERATIONS */)
			{
				break;
			}
		}
		return instances;
	}
	catch (Exception e)
	{
		e.printStackTrace();
		throw new IllegalArgumentException("Invalid testrule: " + rule.rule);
	}
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:27,代码来源:RecurrenceEquivalenceTest.java

示例10: testGetIteratorSyncedStartWithCount

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void testGetIteratorSyncedStartWithCount() throws Exception
{
    AbstractRecurrenceAdapter.InstanceIterator iterator = new RecurrenceRuleAdapter(new RecurrenceRule("FREQ=MONTHLY;COUNT=3"))
            .getIterator(TimeZone.getTimeZone("Europe/Berlin"), DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp());

    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(false));
    assertThat(iterator.hasNext(), is(false));
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:25,代码来源:RecurrenceRuleAdapterTest.java

示例11: testGetIteratorSyncedStartWithUntil

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void testGetIteratorSyncedStartWithUntil() throws Exception
{
    AbstractRecurrenceAdapter.InstanceIterator iterator = new RecurrenceRuleAdapter(new RecurrenceRule("FREQ=MONTHLY;UNTIL=20170312T113012Z"))
            .getIterator(TimeZone.getTimeZone("Europe/Berlin"), DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp());

    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170210T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170310T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(false));
    assertThat(iterator.hasNext(), is(false));
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:25,代码来源:RecurrenceRuleAdapterTest.java

示例12: testGetIteratorUnsyncedStartWithCount

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Test
public void testGetIteratorUnsyncedStartWithCount() throws Exception
{
    AbstractRecurrenceAdapter.InstanceIterator iterator = new RecurrenceRuleAdapter(new RecurrenceRule("FREQ=MONTHLY;COUNT=3;BYMONTHDAY=11"))
            .getIterator(TimeZone.getTimeZone("Europe/Berlin"), DateTime.parse("Europe/Berlin", "20170110T113012").getTimestamp());

    // note the unsynced start is not a result, it's added separately by `RecurrenceSet`
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170111T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170111T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170111T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170211T113012").getTimestamp()));
    assertThat(iterator.peek(), is(DateTime.parse("Europe/Berlin", "20170211T113012").getTimestamp()));
    assertThat(iterator.next(), is(DateTime.parse("Europe/Berlin", "20170211T113012").getTimestamp()));
    assertThat(iterator.hasNext(), is(false));
    assertThat(iterator.hasNext(), is(false));
}
 
开发者ID:dmfs,项目名称:lib-recur,代码行数:21,代码来源:RecurrenceRuleAdapterTest.java

示例13: getNextValidTime

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
public Date getNextValidTime() {
  final long now = System.currentTimeMillis();
  DateTime startDateTime = new DateTime(dtStart.getYear(), (dtStart.getMonthOfYear() - 1), dtStart.getDayOfMonth(),
    dtStart.getHourOfDay(), dtStart.getMinuteOfHour(), dtStart.getSecondOfMinute());
  RecurrenceRuleIterator timeIterator = recurrenceRule.iterator(startDateTime);

  int count = 0;
  while (timeIterator.hasNext() && (count < MAX_ITERATIONS || (recurrenceRule.hasPart(Part.COUNT) && count < recurrenceRule.getCount()))) {
    count ++;
    long nextRunAtTimestamp = timeIterator.nextMillis();
    if (nextRunAtTimestamp >= now) {
      return new Date(nextRunAtTimestamp);
    }
  }
  return null;
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:17,代码来源:RFC5545Schedule.java

示例14: insert

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Override
public TaskAdapter insert(SQLiteDatabase db, TaskAdapter task, boolean isSyncAdapter)
{
    updateFields(db, task, isSyncAdapter);

    if (!isSyncAdapter)
    {
        // set created date for tasks created on the device
        task.set(TaskAdapter.CREATED, DateTime.now());
    }

    TaskAdapter result = mDelegate.insert(db, task, isSyncAdapter);

    if (isSyncAdapter && result.isRecurring())
    {
        // task is recurring, update ORIGINAL_INSTANCE_ID of all exceptions that may already exists
        ContentValues values = new ContentValues(1);
        TaskAdapter.ORIGINAL_INSTANCE_ID.setIn(values, result.id());
        db.update(TaskDatabaseHelper.Tables.TASKS, values, TaskContract.Tasks.ORIGINAL_INSTANCE_SYNC_ID + "=? and "
                + TaskContract.Tasks.ORIGINAL_INSTANCE_ID + " is null", new String[] { result.valueOf(TaskAdapter.SYNC_ID) });
    }
    return result;
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:24,代码来源:AutoCompleting.java

示例15: getFrom

import org.dmfs.rfc5545.DateTime; //导入依赖的package包/类
@Override
public DateTime getFrom(ContentValues values)
{
    Long timestamp = values.getAsLong(mTimestampField);
    if (timestamp == null)
    {
        // if the time stamp is null we return null
        return null;
    }
    // create a new Time for the given time zone, falling back to UTC if none is given
    String timezone = mTzField == null ? null : values.getAsString(mTzField);
    DateTime value = new DateTime(timezone == null ? DateTime.UTC : TimeZone.getTimeZone(timezone), timestamp);

    // cache mAlldayField locally
    String allDayField = mAllDayField;

    // set the allday flag appropriately
    Integer allDayInt = allDayField == null ? null : values.getAsInteger(allDayField);

    if ((allDayInt != null && allDayInt != 0) || (allDayField == null && mAllDayDefault))
    {
        value = value.toAllDay();
    }

    return value;
}
 
开发者ID:dmfs,项目名称:opentasks,代码行数:27,代码来源:DateTimeFieldAdapter.java


注:本文中的org.dmfs.rfc5545.DateTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。