@Override public DateTime parseUpdated(Element element) { checkNotNull(element); String dateTime = element.getAttribute("title"); if (dateTime.equals("")) { dateTime = element.getTextContent(); } try { return DateTime.parseDateTime(dateTime); } catch (RuntimeException e) { return null; } } }
/** * Set date/time value. * * @throws NullPointerException if argument is null. */ public void setDateTime(DateTime value) { if (value == null) { throw new NullPointerException("value must not be null"); } dateTimeValue = value; super.setValue(value.toString()); }
@Override protected void validate() throws IllegalStateException { if (startTime == null) { throwExceptionForMissingAttribute(START_TIME); } if (endTime != null) { if (startTime.compareTo(endTime) > 0) { throw new IllegalStateException( "g:when/@startTime must be less than or equal to g:when/@endTime."); } if (startTime.isDateOnly() != endTime.isDateOnly()) { throw new IllegalStateException( (startTime.isDateOnly() ? "Date" : "Date/time") + " value expected."); } } }
/** * Parses an XML value that's either an xs:date or xs:dateTime string. * * @throws NumberFormatException * Invalid RFC 3339 date or date/time string. */ public static DateTime parseDateTimeChoice(String value) throws NumberFormatException { NumberFormatException exception; try { return DateTime.parseDateTime(value); } catch (NumberFormatException e) { exception = e; } try { return DateTime.parseDate(value); } catch (NumberFormatException e) { exception = e; } throw exception; }
/** * Returns hash code that is based on the date/time value that the object * holds. */ @Override public int hashCode() { if (dateTimeValue == null) { return 0; } return dateTimeValue.hashCode(); }
/** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#DATE}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param date attribute value * @return the attribute object that has been created and added to the item * @exception IllegalArgumentException if the attribute value is * not only a date, but a date and a time (see * {@link com.google.gdata.data.DateTime#isDateOnly()}) */ public GoogleBaseAttribute addDateAttribute(String name, DateTime date) { if (!date.isDateOnly()) { throw new IllegalArgumentException("DateTime should be only a date, " + "NOT a date and a time. Call addDateTimeAttribute() instead."); } return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.DATE, date.toString())); }
public MediaFileSource(File mediaFile, String mediaType) { super(mediaType); this.mediaFile = mediaFile; this.contentLength = mediaFile.length(); this.lastModified = new DateTime(mediaFile.lastModified()); this.name = mediaFile.getName(); }
public void setUpdated(DateTime v) { if (v != null && v.getTzShift() == null) { throw new IllegalArgumentException("Entry.updated must have a timezone."); } state.updated = v; }
/** * Creates a new hAtom "updated" element for the given entry. */ static XmlElement getUpdatedElement(BaseContentEntry<?> entry) { checkNotNull(entry); XmlElement element = new XmlElement("abbr"); element.setAttribute("class", "updated"); element.setAttribute("title", entry.getUpdated().toString()); DateTime jodaTime = new DateTime(entry.getUpdated().getValue(), DateTimeZone.UTC); element.addText(jodaTime.toString(formatter)); return element; } }
/** Converts a string containing a date or a date and a time to a DateTime. */ static DateTime toDateOrDateTime(String text) { if (text == null) { return null; } return DateTime.parseDateTimeChoice(text); }
/** Formats the value as a human-readable string. */ public String toUiString() { StringBuilder sb = new StringBuilder(); Calendar dateTime = new GregorianCalendar(GMT); long localTime = value; if (tzShift != null) { localTime += tzShift.longValue() * 60000; } dateTime.setTimeInMillis(localTime); try { appendInt(sb, dateTime.get(Calendar.YEAR), 4); sb.append('-'); appendInt(sb, dateTime.get(Calendar.MONTH) + 1, 2); sb.append('-'); appendInt(sb, dateTime.get(Calendar.DAY_OF_MONTH), 2); if (!dateOnly) { sb.append(' '); appendInt(sb, dateTime.get(Calendar.HOUR_OF_DAY), 2); sb.append(':'); appendInt(sb, dateTime.get(Calendar.MINUTE), 2); } } catch (ArrayIndexOutOfBoundsException e) { throw new RuntimeException(e); } return sb.toString(); }
@Override protected void consumeAttributes(AttributeHelper helper) throws ParseException { super.consumeAttributes(helper); try { date = DateTime.parseDate(helper.consumeContent(true)); } catch (NumberFormatException e) { throw new ParseException("Invalid date. Expected format: YYYY-MM-DD"); } } }
/** * Orders two entries such that the more recently updated entry comes first. */ @Override public int compare(BaseContentEntry<?> e1, BaseContentEntry<?> e2) { int compare = e1.getUpdated().compareTo(e2.getUpdated()); return forward ? compare : -compare; } }
/** * Sets the date. * * @param date a {@link DateTime} that contains only a date. See * {@link DateTime#setDateOnly}. */ public void setDate(DateTime date) { if (date != null && !date.isDateOnly()) { throw new IllegalStateException( "Object should be only a date, not a date and a time"); } this.date = date; }
/** * Parses an XML value that's either an xs:date or xs:dateTime string. * * @throws NumberFormatException * Invalid RFC 3339 date or date/time string. */ public static DateTime parseDateTimeChoice(String value) throws NumberFormatException { NumberFormatException exception; try { return DateTime.parseDateTime(value); } catch (NumberFormatException e) { exception = e; } try { return DateTime.parseDate(value); } catch (NumberFormatException e) { exception = e; } throw exception; }
/** * Returns hash code that is based on the date/time value that the object * holds. */ @Override public int hashCode() { if (dateTimeValue == null) { return 0; } return dateTimeValue.hashCode(); }
/** * Adds an attribute of type * {@link com.google.api.gbase.client.GoogleBaseAttributeType#DATE}. * * This method will never remove an attribute, even if it has * the same name as the new attribute. If you would like to set * an attribute that can only appear once, call * {@link #removeAttributes(String, GoogleBaseAttributeType)} first. * * @param name attribute name * @param date attribute value * @return the attribute object that has been created and added to the item * @exception IllegalArgumentException if the attribute value is * not only a date, but a date and a time (see * {@link com.google.gdata.data.DateTime#isDateOnly()}) */ public GoogleBaseAttribute addDateAttribute(String name, DateTime date) { if (!date.isDateOnly()) { throw new IllegalArgumentException("DateTime should be only a date, " + "NOT a date and a time. Call addDateTimeAttribute() instead."); } return addAttribute(new GoogleBaseAttribute(name, GoogleBaseAttributeType.DATE, date.toString())); }
public static DateTime now() { return new DateTime(new Date(), GMT); }
public void setEdited(DateTime v) { if (v != null && v.getTzShift() == null) { throw new IllegalArgumentException("Entry.edited must have a timezone."); } state.edited = v; }
/** Converts a string containing a date or a date and a time to a DateTime. */ static DateTime toDateOrDateTime(String text) { if (text == null) { return null; } return DateTime.parseDateTimeChoice(text); }