本文整理了Java中net.fortuna.ical4j.model.Date
类的一些代码示例,展示了Date
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date
类的具体详情如下:
包路径:net.fortuna.ical4j.model.Date
类名称:Date
[英]A representation of the DATE object defined in RFC5445.
NOTE: iCal4j calculates the timezone of Date objects by default. In the iCalendar specification a DATE object doesn't really have a timezone associated with it, but in the ical4j implementation it does (as it is based on a java.util.Date object). An unfortunate side effect of this is that a Date object can be affected by daylight savings rules for the associated timezone. So currently ical4j offers two approaches to setting the timezone:
By default option 1 is used, but you can override this with the following flag in the ical4j.properties file: net.fortuna.ical4j.timezone.date.floating=true
Alternatively you can avoid using the constructor that accepts a java.util.Date object, and instead provide a date string value. This should always display the correct value, however when the local timezone is used any calculations (recurrences, etc.) may still be affect by DST rules.
Extract from RFC5545:
3.3.4. Date
Value Name: DATE
Purpose: This value type is used to identify values that contain a
calendar date.
Format Definition: This value type is defined by the following
notation:
date = date-value
date-value = date-fullyear date-month date-mday
date-fullyear = 4DIGIT
date-month = 2DIGIT ;01-12
date-mday = 2DIGIT ;01-28, 01-29, 01-30, 01-31
;based on month/year
Description: If the property permits, multiple "date" values are
specified as a COMMA-separated list of values. The format for the
value type is based on the [ISO.8601.2004] complete
representation, basic format for a calendar date. The textual
format specifies a four-digit year, two-digit month, and two-digit
day of the month. There are no separator characters between the
year, month, and day component text.
No additional content value encoding (i.e., BACKSLASH character
encoding, see Section 3.3.11) is defined for this value type.
Example: The following represents July 14, 1997:
19970714
[中]RFC5445中定义的日期对象的表示形式。
注意:默认情况下,iCal4j计算日期对象的时区。在iCalendar规范中,日期对象实际上没有与之关联的时区,但在ical4j实现中,它有与之关联的时区(因为它基于java.util.DATE对象)。这样做的一个不幸的副作用是,日期对象可能会受到关联时区的夏令时规则的影响。因此,目前ical4j提供了两种设置时区的方法:
1.使用UTC时间(无DST规则,但取决于日期的构造方式,它可能会更改显示值
1.使用本地时区(在极少数情况下,DST规则可能会影响显示值)。
默认情况下,使用选项1,但您可以在ical4j中使用以下标志覆盖此选项。属性文件:net.fortuna.ical4j.timezone.date.floating=true
或者,您可以避免使用接受java的构造函数。util。对象,而是提供一个日期字符串值。这应始终显示正确的值,但是当使用本地时区时,任何计算(重现等)仍可能受到DST规则的影响。
摘自RFC5545:
3.3.4. Date
Value Name: DATE
Purpose: This value type is used to identify values that contain a
calendar date.
Format Definition: This value type is defined by the following
notation:
date = date-value
date-value = date-fullyear date-month date-mday
date-fullyear = 4DIGIT
date-month = 2DIGIT ;01-12
date-mday = 2DIGIT ;01-28, 01-29, 01-30, 01-31
;based on month/year
Description: If the property permits, multiple "date" values are
specified as a COMMA-separated list of values. The format for the
value type is based on the [ISO.8601.2004] complete
representation, basic format for a calendar date. The textual
format specifies a four-digit year, two-digit month, and two-digit
day of the month. There are no separator characters between the
year, month, and day component text.
No additional content value encoding (i.e., BACKSLASH character
encoding, see Section 3.3.11) is defined for this value type.
Example: The following represents July 14, 1997:
19970714
代码示例来源:origin: PrivacyApps/calendar-import-export
private Date utcDateFromMs(long ms) {
// This date will be UTC provided the default false value of the iCal4j property
// "net.fortuna.ical4j.timezone.date.floating" has not been changed.
return new Date(ms);
}
代码示例来源:origin: caldav4j/caldav4j
protected Map<String, String> getAttributes() {
Map<String, String> m = new LinkedHashMap<>();
if (start != null) {
m.put(ATTR_START, start.toString());
}
if (end != null) {
m.put(ATTR_END, end.toString());
}
return m;
}
代码示例来源:origin: micromata/projectforge
public static java.sql.Date getSqlDate(final net.fortuna.ical4j.model.Date ical4jDate)
{
if (ical4jDate == null) {
return null;
}
return new java.sql.Date(ical4jDate.getTime());
}
代码示例来源:origin: org.bedework/bw-ical4j-cl
/**
* @param value a string representation of a date
* @throws ParseException where the specified string is not a valid date
*/
public Date(final String value) throws ParseException {
this();
setTime(getFormat().parse(value).getTime());
}
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
if (dtend.before(dtstart)) {
dtend = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(
new Dur(0, 0, 0, 0).getTime(dtstart), dtstart);
if (dtend.before(dtstart)) {
dtend = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(
new Dur(1, 0, 0, 0).getTime(dtstart), dtstart);
String key = instance.getRid().toString();
if (dtstart.before(rangeEnd)
&& dtend.after(rangeStart)) {
put(key, instance);
modified = true;
boolean timeShift = dtstart.compareTo(riddt) != 0;
Dur offsetTime = timeShift ? new Dur(riddt, dtstart) : null;
Dur newDuration = timeShift ? new Dur(dtstart, dtend) : null;
originalstart, false, false);
remove(ikey);
put(newinstance.getRid().toString(), newinstance);
modified = true;
代码示例来源:origin: ical4j/ical4j
private void getDates(java.util.Date startRange, java.util.Date endRange, java.util.Date eventStart, Recur recur) {
net.fortuna.ical4j.model.Date start = new net.fortuna.ical4j.model.Date(startRange);
net.fortuna.ical4j.model.Date end = new net.fortuna.ical4j.model.Date(endRange);
net.fortuna.ical4j.model.Date seed = new net.fortuna.ical4j.model.Date(eventStart);
DateList dates = recur.getDates(seed, start, end, Value.DATE);
for (int i=0; i<dates.size(); i++) {
log.info("date_" + i + " = " + dates.get(i).toString());
}
}
代码示例来源:origin: org.bedework.caleng/bw-calendar-engine-ical
Date d = (Date)o1;
if (d.before(rr.rangeStart)) {
rr.rangeStart = d;
Date maxRangeEnd = new Date(dur.getTime(rr.rangeStart));
Date dt = pend.makeDate();
if (dt.before(maxRangeEnd)) {
maxRangeEnd = dt;
maxRangeEnd);
if ((rr.rangeEnd == null) || (rr.rangeEnd.after(maxRangeEnd))) {
rr.rangeEnd = maxRangeEnd;
代码示例来源:origin: micromata/projectforge
@Override
public Property toVEvent(final TeamEventDO event)
{
net.fortuna.ical4j.model.Date date;
if (event.isAllDay() == true) {
final Date endUtc = CalendarUtils.getUTCMidnightDate(event.getEndDate());
final org.joda.time.DateTime jodaTime = new org.joda.time.DateTime(endUtc);
// TODO sn should not be done
// requires plus 1 because one day will be omitted by calendar.
final net.fortuna.ical4j.model.Date fortunaEndDate = new net.fortuna.ical4j.model.Date(jodaTime.plusDays(1).toDate());
date = new net.fortuna.ical4j.model.Date(fortunaEndDate.getTime());
} else {
date = new DateTime(event.getEndDate());
((net.fortuna.ical4j.model.DateTime) date).setTimeZone(TIMEZONE_REGISTRY.getTimeZone(event.getTimeZone().getID()));
}
return new DtEnd(date);
}
代码示例来源:origin: ical4j/ical4j
final Date candidateSeed = Dates.getInstance(cal.getTime(), value);
if (getUntil() != null && candidate != null && candidate.after(getUntil())) {
break;
candidate = candidate1;
if (!candidate.before(seed)) {
if (!candidate.after(startDate)) {
invalidCandidateCount++;
} else if (getCount() > 0
break;
} else if (!(getUntil() != null
&& candidate.after(getUntil()))) {
return candidate;
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
/**
* Evaluates property.
* @param property The proeprty.
* @param filter The time range filter.
* @return The result.
*/
private boolean evaluate(Property property, TimeRangeFilter filter) {
if(!(property instanceof DateProperty) ) {
return false;
}
DateProperty dateProp = (DateProperty) property;
Date date = dateProp.getDate();
return date.before(filter.getPeriod().getEnd()) &&
date.after(filter.getPeriod().getStart()) ||
date.equals(filter.getPeriod().getStart()) ;
}
代码示例来源:origin: ical4j/ical4j
/**
* Returns the latest applicable timezone observance for the specified date.
* @param date the latest possible date for a timezone observance onset
* @return the latest applicable timezone observance for the specified date or null if there are no applicable
* observances
*/
public final Observance getApplicableObservance(final Date date) {
Observance latestObservance = null;
Date latestOnset = null;
for (final Observance observance : getObservances()) {
final Date onset = observance.getLatestOnset(date);
if (latestOnset == null
|| (onset != null && onset.after(latestOnset))) {
latestOnset = onset;
latestObservance = observance;
}
}
return latestObservance;
}
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
/**
* ICU4J generates VTIMEZONE RRULEs with floating UNTIL, which results
* in a bad VTIMEZONE because the UNTIL is converted to UTC, which will
* be different depending on the default timezone of the server. So
* to fix this, always add a day to UNTIL to make sure the RRULE
* doesn't fall short. This should work for most timezones as timezones
* don't usually change from day to day. Hopefully this is fixed in
* an icu4j update.
* @param vtz
*/
protected static void fixIcuVTimeZone(VTimeZone vtz) {
for(Iterator<Observance> obIt = vtz.getObservances().iterator();obIt.hasNext();) {
PropertyList<RRule> rruleList= obIt.next().getProperties(Property.RRULE);
for(RRule rrule: rruleList) {
Recur recur = rrule.getRecur();
if(recur.getUntil()!=null) {
recur.getUntil().setTime(recur.getUntil().getTime() + ONE_DAY);
}
}
}
}
代码示例来源:origin: org.mnode.ical4j/ical4j
/**
* {@inheritDoc}
*/
public final void setTime(final long time) {
super.setTime(time);
// need to check for null time due to Android java.util.Date(long)
// constructor
// calling this method..
if (this.time != null) {
this.time.setTime(time);
}
}
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
long delta = 0;
if(!newStartDate.equals(lastRecurrenceId)) {
delta = newStartDate.getTime() - lastRecurrenceId.getTime();
boolean isDtStartMissing = dtStart.equals(recurrenceId)
&& event.isAnyTime() == null;
new java.util.Date(recurrenceId.getTime() + delta);
recurrenceId = Dates.getInstance(newRidTime, recurrenceId);
if(recurrenceId.equals(newStartDate) && delta!=0) {
event.setStartDate(newStartDate);
代码示例来源:origin: org.bedework.caleng/bw-calendar-engine-ical
int counted = 0;
while ((counted < count) && (start.before(maxRangeEnd))) {
Date end = new DateTime(days100.getTime(start));
DateList dl = r.getDates(seed, start, end, Value.DATE_TIME);
代码示例来源:origin: ical4j/ical4j
/**
* {@inheritDoc}
*/
public boolean equals(final Object arg0) {
// TODO: what about compareTo, before, after, etc.?
if (arg0 instanceof DateTime) {
return new EqualsBuilder().append(time, ((DateTime) arg0).time)
.isEquals();
}
return super.equals(arg0);
}
代码示例来源:origin: ical4j/ical4j
@Override
public int compareTo(DtStamp o) {
return getDate().compareTo(o.getDate());
}
代码示例来源:origin: 1and1/cosmo
if (dtend.before(dtstart)) {
dtend = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(
new Dur(0, 0, 0, 0).getTime(dtstart), dtstart);
if (dtend.before(dtstart)) {
dtend = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(
new Dur(1, 0, 0, 0).getTime(dtstart), dtstart);
String key = instance.getRid().toString();
if (dtstart.before(rangeEnd)
&& dtend.after(rangeStart)) {
put(key, instance);
modified = true;
boolean timeShift = dtstart.compareTo(riddt) != 0;
Dur offsetTime = timeShift ? new Dur(riddt, dtstart) : null;
Dur newDuration = timeShift ? new Dur(dtstart, dtend) : null;
originalstart, false, false);
remove(ikey);
put(newinstance.getRid().toString(), newinstance);
modified = true;
代码示例来源:origin: ical4j/ical4j
/**
* @return
* @throws ParseException
*/
public static TestSuite suite() throws ParseException {
TestSuite suite = new TestSuite();
suite.addTest(new DateListTest(new DateList(), 0));
suite.addTest(new DateListTest(new Date().toString(), Value.DATE, 1));
suite.addTest(new DateListTest(new DateTime().toString(), Value.DATE_TIME, 1));
suite.addTest(new DateListTest(new DateTime(123).toString() + "," + new DateTime(999).toString(), Value.DATE_TIME, 2));
return suite;
}
}
代码示例来源:origin: micromata/projectforge
@Override
public boolean fromVEvent(final TeamEventDO event, final VEvent vEvent)
{
final boolean isAllDay = this.isAllDay(vEvent);
if (vEvent.getProperties().getProperties(Property.DTEND).isEmpty()) {
return false;
}
if (isAllDay) {
// TODO sn change behaviour to iCal standard
final org.joda.time.DateTime jodaTime = new org.joda.time.DateTime(vEvent.getEndDate().getDate());
final net.fortuna.ical4j.model.Date fortunaEndDate = new net.fortuna.ical4j.model.Date(jodaTime.plusDays(-1).toDate());
event.setEndDate(new Timestamp(fortunaEndDate.getTime()));
} else {
event.setEndDate(ICal4JUtils.getSqlTimestamp(vEvent.getEndDate().getDate()));
}
return true;
}
}
内容来源于网络,如有侵权,请联系作者删除!