本文整理汇总了Java中net.fortuna.ical4j.model.DateTime.isUtc方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.isUtc方法的具体用法?Java DateTime.isUtc怎么用?Java DateTime.isUtc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.fortuna.ical4j.model.DateTime
的用法示例。
在下文中一共展示了DateTime.isUtc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: normalizeUTCDateTimeToDefaultOffset
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的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);
}
}
示例4: 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);
}
示例5: 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 = DomUtils.getAttribute(element, ATTR_CALDAV_START);
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 =
DomUtils.getAttribute(element, ATTR_CALDAV_END);
if (end == null) {
//add one year to date start Iphone ios7 bug
end = addOneYearToDateStart(start);
//throw new ParseException("CALDAV:comp-filter time-range requires an end time", -1);
}
DateTime trend = new DateTime(end);
if (! trend.isUtc()) {
throw new ParseException("CALDAV:param-filter timerange end must be UTC", -1);
}
setPeriod(new Period(trstart, trend));
setTimezone(timezone);
}
示例6: copyNormalisedDate
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
* Copy a Date/DateTime and normalise to UTC if its not floating.
*
* @param date The date.
* @return The date.
*/
private Date copyNormalisedDate(Date date) {
if (date instanceof DateTime) {
DateTime dt = new DateTime(date);
if (!dt.isUtc() && dt.getTimeZone() != null) {
dt.setUtc(true);
}
return dt;
} else {
return new Date(date);
}
}
示例7: isFloating
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
* Determine if a Date is floating. A floating Date is a Date
* instance or a DateTime that is not utc and does not have a timezone.
* @param date The date.
* @return true if the date is floating, otherwise false
*/
public static boolean isFloating(Date date) {
if(date instanceof DateTime) {
DateTime dt = (DateTime) date;
return !dt.isUtc() && dt.getTimeZone()==null;
} else {
return true;
}
}
示例8: adjustFloatingDateIfNecessary
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
* Adjust a floating time if a timezone is present. A floating time
* is initially created with the default system timezone. If a timezone
* if present, we need to adjust the floating time to be in specified
* timezone. This allows a server in the US to return floating times for
* a query made by someone whos timezone is in Australia. If no timezone is
* set for the InstanceList, then the system default timezone will be
* used in floating time calculations.
* <p/>
* What happens is a floating time will get converted into a
* date/time with a timezone. This is ok for comparison and recurrence
* generation purposes. Note that Instances will get indexed as a UTC
* date/time and for floating DateTimes, the the recurrenceId associated
* with the Instance loses its "floating" property.
*
* @param date The date.
* @return The date.
*/
private Date adjustFloatingDateIfNecessary(Date date) {
if (timezone == null || !(date instanceof DateTime)) {
return date;
}
DateTime dtDate = (DateTime) date;
if (dtDate.isUtc() || dtDate.getTimeZone() != null) {
return date;
}
try {
return new DateTime(dtDate.toString(), timezone);
} catch (ParseException e) {
throw new CosmoParseException("error parsing date", e);
}
}