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


Java DateTime类代码示例

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


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

示例1: parseAppointmenttoCalendar

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Methods to parse Appointment to iCalendar according RFC 2445
 *
 * @param appointment to be converted to iCalendar
 * @return iCalendar representation of the Appointment
 */
public Calendar parseAppointmenttoCalendar(Appointment appointment) {
	String tzid = parseTimeZone(null, appointment.getOwner()).getID();

	TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

	net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid);
	if (timeZone == null) {
		throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid);
	}

	Calendar icsCalendar = new Calendar();
	icsCalendar.getProperties().add(new ProdId("-//Events Calendar//Apache Openmeetings//EN"));
	icsCalendar.getProperties().add(Version.VERSION_2_0);
	icsCalendar.getProperties().add(CalScale.GREGORIAN);
	icsCalendar.getComponents().add(timeZone.getVTimeZone());

	DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd());

	VEvent meeting = new VEvent(start, end, appointment.getTitle());
	meeting = addVEventpropsfromAppointment(appointment, meeting);
	icsCalendar.getComponents().add(meeting);

	return icsCalendar;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:31,代码来源:IcalUtils.java

示例2: parseAppointmentstoCalendar

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Parses a List of Appointments into a VCALENDAR component.
 *
 * @param appointments List of Appointments for the Calendar
 * @param ownerId      Owner of the Appointments
 * @return VCALENDAR representation of the Appointments
 */
public Calendar parseAppointmentstoCalendar(List<Appointment> appointments, Long ownerId) {
	String tzid = parseTimeZone(null, userDao.get(ownerId)).getID();

	TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();

	net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid);
	if (timeZone == null) {
		throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid);
	}

	Calendar icsCalendar = new Calendar();
	icsCalendar.getProperties().add(new ProdId(PROD_ID));
	icsCalendar.getProperties().add(Version.VERSION_2_0);
	icsCalendar.getProperties().add(CalScale.GREGORIAN);
	icsCalendar.getComponents().add(timeZone.getVTimeZone());

	for (Appointment appointment : appointments) {
		DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd());

		VEvent meeting = new VEvent(start, end, appointment.getTitle());
		meeting = addVEventpropsfromAppointment(appointment, meeting);
		icsCalendar.getComponents().add(meeting);
	}
	return icsCalendar;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:33,代码来源:IcalUtils.java

示例3: testPinFloatingTime

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Tests pin floating time.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testPinFloatingTime() throws Exception {
    TimeZone tz1 = TIMEZONE_REGISTRY.getTimeZone("America/Chicago");
   
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new Date("20070101"), tz1).toString());
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"), tz1).toString());
    
    
    TimeZone tz2 = TIMEZONE_REGISTRY.getTimeZone("America/Los_Angeles");
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new Date("20070101"), tz1).toString());
    Assert.assertEquals("20070101T000000", ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"), tz1).toString());

    Assert.assertTrue(ICalendarUtils.pinFloatingTime(
            new Date("20070101"), tz1).before(
            ICalendarUtils.pinFloatingTime(new Date("20070101"),
                    tz2)));
    Assert.assertTrue(ICalendarUtils.pinFloatingTime(
            new DateTime("20070101T000000"), tz1).before(
            ICalendarUtils.pinFloatingTime(new DateTime("20070101T000000"),
                    tz2)));
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:26,代码来源:ICalendarUtilsTest.java

示例4: testEventStampTimeRangeQuery

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Tests event stamp time range query.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testEventStampTimeRangeQuery() throws Exception {
    NoteItemFilter filter = new NoteItemFilter();
    EventStampFilter eventFilter = new EventStampFilter();
    Period period = new Period(new DateTime("20070101T100000Z"), new DateTime("20070201T100000Z"));
    eventFilter.setPeriod(period);
    eventFilter.setTimezone(registry.getTimeZone("America/Chicago"));
    
    CollectionItem parent = new HibCollectionItem();
    filter.setParent(parent);
    filter.getStampFilters().add(eventFilter);
    QueryImpl<Item> query =  queryBuilder.buildQuery(session, filter);
    Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, "
            + "HibBaseEventStamp es where pd.primaryKey.collection=:parent and es.item=i "
            + "and ( (es.timeRangeIndex.isFloating=true and "
            + "es.timeRangeIndex.startDate < '20070201T040000' and "
            + "es.timeRangeIndex.endDate > '20070101T040000') or "
            + "(es.timeRangeIndex.isFloating=false and "
            + "es.timeRangeIndex.startDate < '20070201T100000Z' and "
            + "es.timeRangeIndex.endDate > '20070101T100000Z') or "
            + "(es.timeRangeIndex.startDate=es.timeRangeIndex.endDate and "
            + "(es.timeRangeIndex.startDate='20070101T040000' or "
            + "es.timeRangeIndex.startDate='20070101T100000Z')))", query.getQueryString());
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:29,代码来源:StandardItemFilterProcessorTest.java

示例5: setDatePropertyValue

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Sets date property value
 * @param prop The date property.
 * @param date The date.
 */
protected void setDatePropertyValue(DateProperty prop, Date date) {
    if (prop == null) {
        return;
    }
    Value value = (Value) prop.getParameters()
            .getParameter(Parameter.VALUE);
    if (value != null) {
        prop.getParameters().remove(value);
    }

    // Add VALUE=DATE for Date values, otherwise
    // leave out VALUE=DATE-TIME because it is redundant
    if (!(date instanceof DateTime)) {
        prop.getParameters().add(Value.DATE);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:22,代码来源:MockBaseEventStamp.java

示例6: testGetNowCollection

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Tests get now collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetNowCollection() throws Exception {
    CollectionItem calendar = (CollectionItem) contentDao.findItemByUid(CALENDAR_UID);
    TriageStatusQueryContext context =
        new TriageStatusQueryContext(TriageStatus.LABEL_NOW, new DateTime("20070601T083000Z"), null);
    Set<NoteItem> now = queryProcessor.processTriageStatusQuery(calendar, context);
    Assert.assertEquals(5, now.size());
    
    // should be included because triage status is NOW
    verifyItemInSet(now,NOTE_UID + "mod");
    // should be included because its the parent of a modification included
    verifyItemInSet(now,NOTE_UID + "done");
    // should be included because triage status is null
    verifyItemInSet(now, "calendar2_2");
    // should be included because occurence overlaps instant in time
    verifyItemInSet(now,"calendar2_3:20070601T081500Z");
    // should be included because occurrence is included
    verifyItemInSet(now, "calendar2_3");
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:24,代码来源:HibernateTriageStatusQueryProcessorTest.java

示例7: ICalDate

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Constructs an <code>ICalDate</code> from an iCalendar date.
 * @param date The date.
 * @throws UnknownTimeZoneException - if something is wrong this exception is thrown.
 */
public ICalDate(Date date) throws UnknownTimeZoneException {
    if (date instanceof DateTime) {
        value = Value.DATE_TIME;
        tz = ((DateTime) date).getTimeZone();
        // We only support known tzids (Olson for the most part)
        if (tz != null) {
            tz = tzTranslator.translateToOlsonTz(tz);
            // If timezone can't be translated, then datetime will
            // essentiallyi be floating.
            if (tz != null) {
                String id = tz.getVTimeZone().getProperties().
                    getProperty(Property.TZID).getValue();
                tzid = new TzId(id);
            }
        }
    } else {
        value = Value.DATE;
    }
    this.anytime = false;
    text = date.toString();
    this.date = date;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:28,代码来源:ICalDate.java

示例8: pinFloatingTime

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Construct a new DateTime instance for floating times (no timezone).
 * If the specified date is not floating, then the instance is returned. 
 * 
 * This allows a floating time to be converted to an instant in time
 * depending on the specified timezone.
 * 
 * @param date floating date
 * @param tz timezone
 * @return new DateTime instance representing floating time pinned to
 *         the specified timezone
 */
public static DateTime pinFloatingTime(Date date, TimeZone tz) {
    
    try {   
        if(date instanceof DateTime) {
            DateTime dt = (DateTime) date;
            if(dt.isUtc() || dt.getTimeZone()!=null) {
                return dt;
            }
            else {
                return new DateTime(date.toString(), tz);
            }
        }
        else {
            return new DateTime(date.toString() + "T000000", tz);
        }
    } catch (ParseException e) {
        throw new CosmoParseException("error parsing date", e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:32,代码来源:ICalendarUtils.java

示例9: normalizeUTCDateTimeToDate

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Return a Date instance that represents the day that a point in
 * time translates into local time given a timezone.
 * @param utcDateTime point in time
 * @param tz timezone The timezone.
 * @return The date.
 */
public static Date normalizeUTCDateTimeToDate(DateTime utcDateTime, TimeZone tz) {
    if(!utcDateTime.isUtc()) {
        throw new IllegalArgumentException("datetime must be utc");
    }
    
    // if no timezone, use default
    if (tz == null) {
        return new Date(utcDateTime);
    }
    
    DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime);
    copy.setTimeZone(tz);
    
    try {
        return new Date(copy.toString().substring(0, 8));
    } catch (ParseException e) {
        throw new CosmoParseException("error creating Date instance", e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:27,代码来源:ICalendarUtils.java

示例10: testGetAllCollection

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Tests get all collection.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testGetAllCollection() throws Exception {
    CollectionItem calendar = (CollectionItem) contentDao.findItemByUid(CALENDAR_UID);
    TriageStatusQueryContext context =
        new TriageStatusQueryContext(null, new DateTime("20070601T000000Z"), null);
    Set<NoteItem> all = queryProcessor.processTriageStatusQuery(calendar, context);
    Assert.assertEquals(12, all.size());
    
    verifyItemInSet(all,NOTE_UID + "later");
    verifyItemInSet(all,NOTE_UID + "done");
    verifyItemInSet(all,NOTE_UID + "mod");
    verifyItemInSet(all,"calendar2_1:20070529T101500Z");
    verifyItemInSet(all,"calendar2_1:20070605T101500Z");
    verifyItemInSet(all,"calendar2_3:20070531T081500Z");
    verifyItemInSet(all,"calendar2_3:20070601T081500Z");
    verifyItemInSet(all,"calendar2_4:20080508T081500Z");
    verifyItemInSet(all,"calendar2_1");
    verifyItemInSet(all,"calendar2_2");
    verifyItemInSet(all,"calendar2_3");
    verifyItemInSet(all,"calendar2_4");
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:26,代码来源:StandardTriageStatusQueryProcessorTest.java

示例11: TimeRangeFilter

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Construct a TimeRangeFilter object from a DOM Element
 * @param element The DOM Element.
 * @throws ParseException - if something is wrong this exception is thrown.
 */
public TimeRangeFilter(Element element, VTimeZone timezone) throws ParseException {        
    // Get start (must be present)
    String start =
        DomUtil.getAttribute(element, ATTR_CALDAV_START, null);
    if (start == null) {
        throw new ParseException("CALDAV:comp-filter time-range requires a start time", -1);
    }
    
    DateTime trstart = new DateTime(start);
    if (! trstart.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange start must be UTC", -1);
    }

    // Get end (must be present)
    String end =
        DomUtil.getAttribute(element, ATTR_CALDAV_END, null);        
    DateTime trend = end != null ? new DateTime(end) : getDefaultEndDate(trstart);
    
    if (! trend.isUtc()) {
        throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
    }

    setPeriod(new Period(trstart, trend));
    setTimezone(timezone);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:31,代码来源:TimeRangeFilter.java

示例12: setDisplayAlarmTriggerDate

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
/**
 * Sets display alarm trigger date.
 * @param triggerDate The trigger date.
 */
public void setDisplayAlarmTriggerDate(DateTime triggerDate) {
    VAlarm alarm = getDisplayAlarm();
    if (alarm == null) {
        return;
    }
    Trigger oldTrigger = (Trigger) alarm.getProperties().getProperty(Property.TRIGGER);
    if (oldTrigger != null) {
        alarm.getProperties().remove(oldTrigger);
    }
    
    Trigger newTrigger = new Trigger();
    newTrigger.getParameters().add(Value.DATE_TIME);
    newTrigger.setDateTime(triggerDate);
    
    alarm.getProperties().add(newTrigger);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:21,代码来源:MockBaseEventStamp.java

示例13: setDatePropertyValue

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
protected void setDatePropertyValue(DateProperty prop,
                                    Date date) {
    if (prop == null) {
        return;
    }
    Value value = (Value)
        prop.getParameters().getParameter(Parameter.VALUE);
    if (value != null) {
        prop.getParameters().remove(value);
    }
    
    // Add VALUE=DATE for Date values, otherwise
    // leave out VALUE=DATE-TIME because it is redundant
    if(! (date instanceof DateTime)) {
        prop.getParameters().add(Value.DATE);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:18,代码来源:HibBaseEventStamp.java

示例14: fromDateToStringNoTimezone

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
private String fromDateToStringNoTimezone(Date date) {
    if(date==null) {
        return null;
    }
    
    if(date instanceof DateTime) {
        DateTime dt = (DateTime) date;
        // If DateTime has a timezone, then convert to UTC before
        // serializing as String.
        if(dt.getTimeZone()!=null) {
            // clone instance first to prevent changes to original instance
            DateTime copy = new DateTime(dt);
            copy.setUtc(true);
            return copy.toString();
        } else {
            return dt.toString();
        }
    } else {
        return date.toString();
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:22,代码来源:EventStampInterceptor.java

示例15: modifyOldSeries

import net.fortuna.ical4j.model.DateTime; //导入依赖的package包/类
private void modifyOldSeries(NoteItem oldSeries, Date lastRecurrenceId) {
    EventStamp event = StampUtils.getEventStamp(oldSeries);
  
    // We set the end date to 1 second before the begining of the next day
    java.util.Calendar untilDateCalendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    untilDateCalendar.setTime(lastRecurrenceId);
    untilDateCalendar.add(java.util.Calendar.DAY_OF_MONTH, -1);
    untilDateCalendar.set(java.util.Calendar.HOUR_OF_DAY, 23);
    untilDateCalendar.set(java.util.Calendar.MINUTE, 59);
    untilDateCalendar.set(java.util.Calendar.SECOND, 59);
    Date untilDate = Dates.getInstance(untilDateCalendar.getTime(), lastRecurrenceId);
    
    // UNTIL must be UTC according to spec
    if(untilDate instanceof DateTime) {
        ((DateTime) untilDate).setUtc(true);
    }
    List<Recur> recurs = event.getRecurrenceRules();
    for (Recur recur : recurs) {
        recur.setUntil(untilDate);
    }
    
    // TODO: Figure out what to do with RDATEs
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:24,代码来源:ThisAndFutureHelper.java


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