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


Java Date类代码示例

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


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

示例1: getOcurrences

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Expand recurring event for given time-range.
 * @param calendar calendar containing recurring event and modifications
 * @param rangeStart expand start
 * @param rangeEnd expand end
 * @param timezone Optional timezone to use for floating dates.  If null, the
 *        system default is used.
 * @return InstanceList containing all occurences of recurring event during
 *         time range
 */
public InstanceList getOcurrences(Calendar calendar, Date rangeStart, Date rangeEnd, TimeZone timezone) {
    ComponentList vevents = calendar.getComponents().getComponents(
            Component.VEVENT);
    
    List<Component> exceptions = new ArrayList<Component>();
    Component masterComp = null;
    
    // get list of exceptions (VEVENT with RECURRENCEID)
    for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) {
        VEvent event = i.next();
        if (event.getRecurrenceId() != null) {
            exceptions.add(event);
        }
        else {
            masterComp = event; 
        }
        
    }
    
    return getOcurrences(masterComp, exceptions, rangeStart, rangeEnd, timezone);
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:32,代码来源:RecurrenceExpander.java

示例2: testRecurrenceExpanderTimezone

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/***
 * Tests recurrence expander timezone.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test 
public void testRecurrenceExpanderTimezone() throws Exception {
    RecurrenceExpander expander = new RecurrenceExpander();
    Calendar calendar = getCalendar("tz_recurring1.ics");
    
    Date[] range = expander.calculateRecurrenceRange(calendar);
    
    Assert.assertEquals("20070101T100000", range[0].toString());
    Assert.assertEquals("20070119T120000", range[1].toString());
    
    Assert.assertEquals(((DateTime) range[0]).getTimeZone().getID(), "America/Chicago");
    Assert.assertEquals(((DateTime) range[1]).getTimeZone().getID(), "America/Chicago");
    
    calendar = getCalendar("tz_recurring2.ics");
    
    range = expander.calculateRecurrenceRange(calendar);
    
    Assert.assertEquals("20070101T100000", range[0].toString());
    Assert.assertNull(range[1]);
    
    Assert.assertEquals(((DateTime) range[0]).getTimeZone().getID(), "America/Chicago");
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:27,代码来源:RecurrenceExpanderTest.java

示例3: testPinFloatingTime

import net.fortuna.ical4j.model.Date; //导入依赖的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: testRecurrenceExpanderFloating

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Tests reccurence expander floating.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test 
public void testRecurrenceExpanderFloating() throws Exception {
    RecurrenceExpander expander = new RecurrenceExpander();
    Calendar calendar = getCalendar("floating_recurring1.ics");
    
    Date[] range = expander.calculateRecurrenceRange(calendar);
    
    Assert.assertEquals("20070101T100000", range[0].toString());
    Assert.assertEquals("20070119T120000", range[1].toString());
    
    calendar = getCalendar("floating_recurring2.ics");
    range = expander.calculateRecurrenceRange(calendar);
    
    Assert.assertEquals("20070101T100000", range[0].toString());
    Assert.assertNull(range[1]);
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:21,代码来源:RecurrenceExpanderTest.java

示例5: testIsOccurrence

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Tests occurence.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testIsOccurrence() throws Exception {
    RecurrenceExpander expander = new RecurrenceExpander();
    Calendar calendar = getCalendar("floating_recurring3.ics");
    
    
    Assert.assertTrue(expander.isOccurrence(calendar, new DateTime("20070102T100000")));
    Assert.assertFalse(expander.isOccurrence(calendar, new DateTime("20070102T110000")));
    Assert.assertFalse(expander.isOccurrence(calendar, new DateTime("20070102T100001")));

    // test DATE
    calendar = getCalendar("allday_recurring3.ics");
    
    Assert.assertTrue(expander.isOccurrence(calendar, new Date("20070101")));
    Assert.assertFalse(expander.isOccurrence(calendar, new Date("20070102")));
    Assert.assertTrue(expander.isOccurrence(calendar, new Date("20070108")));
    
    // test DATETIME with timezone
    calendar = getCalendar("tz_recurring3.ics");
    TimeZone ctz = TIMEZONE_REGISTRY.getTimeZone("America/Chicago");
    
    Assert.assertTrue(expander.isOccurrence(calendar, new DateTime("20070102T100000", ctz)));
    Assert.assertFalse(expander.isOccurrence(calendar, new DateTime("20070102T110000", ctz)));
    Assert.assertFalse(expander.isOccurrence(calendar, new DateTime("20070102T100001", ctz)));
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:30,代码来源:RecurrenceExpanderTest.java

示例6: addToInstanceList

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
    * Adds to instance list.
    *
    * @param calendar  The calendar.
    * @param instances The instances.
    * @param start     The start.
    * @param end       The end.
    */
   private static void addToInstanceList(Calendar calendar,
                                         InstanceList instances, Date start, Date end) {
       ComponentList<VEvent> vevents = calendar.getComponents().getComponents(VEvent.VEVENT);
Iterator<VEvent> it = vevents.iterator();
       boolean addedMaster = false;
       while (it.hasNext()) {
           VEvent event = (VEvent)it.next();
           if (event.getRecurrenceId() == null) {
               addedMaster = true;
               instances.addComponent(event, start, end);
           } else {
               Assert.assertTrue(addedMaster);
               instances.addOverride(event, start, end);
           }
       }
   }
 
开发者ID:1and1,项目名称:cosmo,代码行数:25,代码来源:InstanceListTest.java

示例7: calculateRecurrenceRange

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Return start and end Date that represent the start of the first 
 * occurrence of a recurring component and the end of the last
 * occurence.  If the recurring component has no end(infinite recurring event),
 * then no end date will be returned.
 * @param calendar Calendar containing master and modification components
 * @return array containing start (located at index 0) and end (index 1) of
 *         recurring component.
 */
public Date[] calculateRecurrenceRange(Calendar calendar) {
    try{
        ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT);
        
        List<Component> exceptions = new ArrayList<Component>();
        Component masterComp = null;
        
        // get list of exceptions (VEVENT with RECURRENCEID)
        for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) {
            VEvent event = i.next();
            if (event.getRecurrenceId() != null) {
                exceptions.add(event);
            }
            else {
                masterComp = event;
            }
            
        }
        
        return calculateRecurrenceRange(masterComp, exceptions);
    } catch (Exception e){
        LOG.error("ERROR in calendar: " + calendar, e);
        throw e;
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:35,代码来源:RecurrenceExpander.java

示例8: ICalDate

import net.fortuna.ical4j.model.Date; //导入依赖的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

示例9: pinFloatingTime

import net.fortuna.ical4j.model.Date; //导入依赖的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

示例10: normalizeUTCDateTimeToDefaultOffset

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Return a DateTime instance that is normalized according to the
 * offset of the specified timezone as compared to the default
 * system timezone.
 * 
 * @param utcDateTime point in time
 * @param tz timezone The timezone.
 * @return The date.
 */
public static Date normalizeUTCDateTimeToDefaultOffset(DateTime utcDateTime, TimeZone tz) {
    if(!utcDateTime.isUtc()) {
        throw new IllegalArgumentException("datetime must be utc");
    }
    
    // if no timezone nothing to do
    if (tz == null) {
        return utcDateTime;
    }
    
    // create copy, and set timezone
    DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime);
    copy.setTimeZone(tz);
    
    
    // Create floating instance of local time, which will give
    // us the correct offset
    try {
        return new DateTime(copy.toString());
    } catch (ParseException e) {
        throw new CosmoParseException("error creating Date instance", e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:33,代码来源:ICalendarUtils.java

示例11: fromDateToStringNoTimezone

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Converts an ical4j Date instance to a string representation.  If the instance
 * is a DateTime and has a timezone, then the string representation will be
 * UTC.
 * @param date date to format
 * @return string representation of date
 */
public static 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,代码行数:29,代码来源:ModificationUidImpl.java

示例12: setDatePropertyValue

import net.fortuna.ical4j.model.Date; //导入依赖的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

示例13: findEvents

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
@Override
public Set<Item> findEvents(CollectionItem collection, Date rangeStart, Date rangeEnd, String timeZoneId,
        boolean expandRecurringEvents) {
    Set<Item> resultSet = new HashSet<>();
    String uid = collection.getUid();
    if (UuidExternalGenerator.get().containsUuid(uid) || UuidSubscriptionGenerator.get().containsUuid(uid)) {
        NoteItemFilter filter = new NoteItemFilter();
        filter.setParent(collection);
        EventStampFilter eventFilter = new EventStampFilter();
        eventFilter.setTimeRange(rangeStart, rangeEnd);
        if (timeZoneId != null) {
            TimeZone timezone = TIMEZONE_REGISTRY.getTimeZone(timeZoneId);
            eventFilter.setTimezone(timezone);
        }
        filter.getStampFilters().add(eventFilter);
        Set<Item> externalItems = this.contentDao.findItems(filter);
        if (externalItems != null) {
            resultSet.addAll(externalItems);
        }
    } else {
        Set<Item> internalItems = calendarDao.findEvents(collection, rangeStart, rangeEnd, timeZoneId,
                expandRecurringEvents);
        resultSet.addAll(internalItems);
    }
    return resultSet;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:27,代码来源:StandardCalendarService.java

示例14: breakRecurringEvent

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Given an existing recurring series and new series, break the
 * existing series at the given occurrence and move all modifications
 * from the existing series that apply to the new series to the 
 * new series.
 * @param oldSeries note representing recurring series to break
 * @param newSeries note representing new series
 * @param occurrence occurrence of old series 
 *        (NoteOccurrence or NoteItem modification) to break old 
 *        series at.
 * @return Set of modifications that need to be removed and added.  
 *         Removals are indicated with isActive==false.
 *         All other active NoteItems are considered additions.
 */
public Set<NoteItem> breakRecurringEvent(NoteItem oldSeries, NoteItem newSeries, NoteItem occurrence) {
    Date lastRid = null;
    if(occurrence instanceof NoteOccurrence) {
        lastRid = ((NoteOccurrence) occurrence).getOccurrenceDate();
    }
    else {
        EventExceptionStamp ees = StampUtils.getEventExceptionStamp(occurrence);
        if(ees==null) {
            throw new IllegalArgumentException("occurence must have an event stamp");
        }
        lastRid = ees.getRecurrenceId();
    }
    
    return breakRecurringEvent(oldSeries, newSeries, lastRid);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:30,代码来源:ThisAndFutureHelper.java

示例15: syncExceptions

import net.fortuna.ical4j.model.Date; //导入依赖的package包/类
/**
 * Sync exceptions.
 * @param exceptions The exceptions.
 * @param masterNote The master note.
 */
private void syncExceptions(Map<Date, VEvent> exceptions,
                            NoteItem masterNote) {
    for (Entry<Date, VEvent> entry : exceptions.entrySet()) {
        syncException(entry.getValue(), masterNote);
    }

    // remove old exceptions
    for (NoteItem noteItem : masterNote.getModifications()) {
        EventExceptionStamp eventException =
            StampUtils.getEventExceptionStamp(noteItem);
        if (eventException==null || !exceptions.containsKey(eventException.getRecurrenceId())) {
            noteItem.setIsActive(false);
        }
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:21,代码来源:EntityConverter.java


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