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


Java TimeZone类代码示例

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


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

示例1: icalResponse

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
private GetEventsResponse icalResponse(Page<EventEntity> eventPage) {
    Calendar calendar = new Calendar();
    calendar.getProperties().add(new ProdId("-//PutPut//iCal4j 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);
    
    eventPage
            .getContent()
            .stream()
            .forEach(event -> {
                TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
                net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(event.getTimezone());
                
                VEvent vEvent = createVEvent(event, timezone);
                
                vEvent.getProperties().add(new Uid(event.getId()));
                vEvent.getProperties().add(new Description(event.getDescription()));
                vEvent.getProperties().add(new Location(event.getLocation()));
                vEvent.getProperties().add(timezone.getVTimeZone().getTimeZoneId());
                
                calendar.getComponents().add(vEvent);
            });
    
    return GetEventsResponse.withCalendarOK(calendar.toString());
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:26,代码来源:EventsResource.java

示例2: createCalendar

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone(timeZone.getID());

    Calendar calendar = new Calendar();
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(new ProdId("openHAB"));
    VEvent vEvent = new VEvent();
    vEvent.getProperties().add(new Summary(calDavEvent.getName()));
    vEvent.getProperties().add(new Description(calDavEvent.getContent()));
    final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
    dtStart.setTimeZone(timezone);
    vEvent.getProperties().add(dtStart);
    final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
    dtEnd.setTimeZone(timezone);
    vEvent.getProperties().add(dtEnd);
    vEvent.getProperties().add(new Uid(calDavEvent.getId()));
    vEvent.getProperties().add(Clazz.PUBLIC);
    vEvent.getProperties()
            .add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
    calendar.getComponents().add(vEvent);

    return calendar;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:25,代码来源:Util.java

示例3: getOcurrences

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

示例4: evaluateVJournalTimeRange

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
/**
 * Evaluates VJournal time range.
 * @param journal The VJournal.
 * @param filter The time range filter.
 * @return The result.
 */
private boolean evaluateVJournalTimeRange(VJournal journal, TimeRangeFilter filter) {
    DtStart start = journal.getStartDate();
  
    if(start==null) {
        return false;
    }
    
    InstanceList instances = new InstanceList();
    if (filter.getTimezone() != null) {
        instances.setTimezone(new TimeZone(filter.getTimezone()));
    }
    instances.addComponent(journal, filter.getPeriod().getStart(),
            filter.getPeriod().getEnd());
    return instances.size() > 0;
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:22,代码来源:CalendarFilterEvaluater.java

示例5: handleEventCompFilter

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
private List<Specification<Item>> handleEventCompFilter(ComponentFilter compFilter, StampFilter eventFilter) {
    List<Specification<Item>> specifications = new ArrayList<>(5);
    TimeRangeFilter trf = compFilter.getTimeRangeFilter();

    // handle time-range filter
    if (trf != null) {
        eventFilter.setPeriod(trf.getPeriod());
        if (trf.getTimezone() != null) {
            eventFilter.setTimezone(new TimeZone(trf.getTimezone()));
        }
    }

    specifications.add(ItemSpecs.stamp(eventFilter.getType(), eventFilter.getIsRecurring(), eventFilter.getStart(), eventFilter.getEnd()));

    for (Iterator it = compFilter.getComponentFilters().iterator(); it.hasNext(); ) {
        ComponentFilter subComp = (ComponentFilter) it.next();
        throw new IllegalArgumentException("unsupported sub component filter: " + subComp.getName());
    }

    for (Iterator it = compFilter.getPropFilters().iterator(); it.hasNext(); ) {
        PropertyFilter propFilter = (PropertyFilter) it.next();
        specifications.add(handleEventPropFilter(propFilter));
    }

    return specifications;
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:27,代码来源:CalendarFilterConverter.java

示例6: testPinFloatingTime

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

示例7: testIsOccurrence

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

示例8: getOcurrences

import net.fortuna.ical4j.model.TimeZone; //导入依赖的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<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 getOcurrences(masterComp, exceptions, rangeStart, rangeEnd, timezone);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:31,代码来源:RecurrenceExpander.java

示例9: translateToOlsonTz

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
/**
 * Given a timezone id, return the equivalent Olson timezone.
 * @param tzId timezone id to translate
 * @return equivalent Olson timezone
 */
public TimeZone translateToOlsonTz(String tzId) {
    
    // First use registry to find Olson tz
    TimeZone translatedTz = registry.getTimeZone(tzId);
    if(translatedTz!=null) {
        return translatedTz;
    }
    
    // Next check for known aliases
    String aliasedTzId = aliases.getProperty(tzId);
    
    // If an aliased id was found, return the Olson tz from the registry
    if(aliasedTzId!=null) {
        return registry.getTimeZone(aliasedTzId);
    }
    
    // Try to find a substring match
    translatedTz = findSubStringMatch(tzId);
    if(translatedTz!=null) {
        return translatedTz;
    }
    
    // failed to find match
    return null;
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:31,代码来源:TimeZoneTranslator.java

示例10: pinFloatingTime

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

示例11: normalizeUTCDateTimeToDate

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

示例12: normalizeUTCDateTimeToDefaultOffset

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

示例13: handleEventCompFilter

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
private void handleEventCompFilter(ComponentFilter compFilter, NoteItemFilter itemFilter) {
    // TODO: handle case of multiple VEVENT filters
    EventStampFilter eventFilter = new EventStampFilter();
    itemFilter.getStampFilters().add(eventFilter);

    TimeRangeFilter trf = compFilter.getTimeRangeFilter();

    // handle time-range filter
    if (trf != null) {
        eventFilter.setPeriod(trf.getPeriod());
        if (trf.getTimezone() != null) {
            eventFilter.setTimezone(new TimeZone(trf.getTimezone()));
        }
    }

    for (ComponentFilter subComp : compFilter.getComponentFilters()) {
        throw new IllegalArgumentException("unsupported sub component filter: " + subComp.getName());
    }

    for (PropertyFilter propFilter : compFilter.getPropFilters()) {
        handleEventPropFilter(propFilter, itemFilter);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:24,代码来源:CalendarFilterConverter.java

示例14: findEvents

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
public Set<Item> findEvents(CollectionItem collection, Date rangeStart, Date rangeEnd, String timezoneId,
        boolean expandRecurringEvents) {

    // Create a NoteItemFilter that filters by parent
    NoteItemFilter itemFilter = new NoteItemFilter();
    itemFilter.setParent(collection);

    // and EventStamp by timeRange
    EventStampFilter eventFilter = new EventStampFilter();

    if (timezoneId != null) {
        TimeZone timeZone = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(timezoneId);
        eventFilter.setTimezone(timeZone);
    }

    eventFilter.setTimeRange(rangeStart, rangeEnd);
    eventFilter.setExpandRecurringEvents(expandRecurringEvents);
    itemFilter.getStampFilters().add(eventFilter);

    try {
        return  itemFilterProcessor.processFilter(itemFilter);            
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:27,代码来源:CalendarDaoImpl.java

示例15: compactTimezones

import net.fortuna.ical4j.model.TimeZone; //导入依赖的package包/类
/**
 * Compact timezones.
 * @param calendar The calendar.
 */
private void compactTimezones(Calendar calendar) {
    
    if (calendar==null) {
        return;
    }

    // Get list of timezones in master calendar and remove all timezone
    // definitions that are in the registry.  The idea is to not store
    // extra data.  Instead, the timezones will be added to the calendar
    // by the getCalendar() api.
    ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE);
    List<VTimeZone> toRemove = new ArrayList<>();
    for(VTimeZone vtz : timezones) {
        String tzid = vtz.getTimeZoneId().getValue();
        TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid);
        //  Remove timezone iff it matches the one in the registry
        if(tz!=null && vtz.equals(tz.getVTimeZone())) {
            toRemove.add(vtz);
        }
    }

    // remove known timezones from master calendar
    calendar.getComponents().removeAll(toRemove);
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:29,代码来源:EntityConverter.java


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