org.apache.jackrabbit.util.ISO8601类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.apache.jackrabbit.util.ISO8601类的一些代码示例,展示了ISO8601类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ISO8601类的具体详情如下:
包路径:org.apache.jackrabbit.util.ISO8601
类名称:ISO8601

ISO8601介绍

[英]The ISO8601 utility class provides helper methods to deal with date/time formatting using a specific ISO8601-compliant format (see ISO 8601).

The currently supported format is:

±YYYY-MM-DDThh:mm:ss.SSSTZD

where:

±YYYY = four-digit year with optional sign where values <= 0 are 
denoting years BCE and values > 0 are denoting years CE, 
e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE, 
0001 denotes the year 1 CE, and so on... 
MM    = two-digit month (01=January, etc.) 
DD    = two-digit day of month (01 through 31) 
hh    = two digits of hour (00 through 23) (am/pm NOT allowed) 
mm    = two digits of minute (00 through 59) 
ss    = two digits of second (00 through 59) 
SSS   = three digits of milliseconds (000 through 999) 
TZD   = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC 
in the form of +hh:mm or -hh:mm

[中]ISO8601实用程序类提供了帮助程序方法,用于使用符合ISO8601的特定格式(请参见ISO 8601)处理日期/时间格式。
当前支持的格式为:

±YYYY-MM-DDThh:mm:ss.SSSTZD

其中:

±YYYY = four-digit year with optional sign where values <= 0 are 
denoting years BCE and values > 0 are denoting years CE, 
e.g. -0001 denotes the year 2 BCE, 0000 denotes the year 1 BCE, 
0001 denotes the year 1 CE, and so on... 
MM    = two-digit month (01=January, etc.) 
DD    = two-digit day of month (01 through 31) 
hh    = two digits of hour (00 through 23) (am/pm NOT allowed) 
mm    = two digits of minute (00 through 59) 
ss    = two digits of second (00 through 59) 
SSS   = three digits of milliseconds (000 through 999) 
TZD   = time zone designator, Z for Zulu (i.e. UTC) or an offset from UTC 
in the form of +hh:mm or -hh:mm

代码示例

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private static String formatTime(long time){
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);
    return ISO8601.format(cal);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Date values are saved with sec resolution
 * @param date jcr data string
 * @return date value in seconds
 */
public static Long dateToLong(String date){
  if( date == null){
    return null;
  }
  //TODO OAK-2204 - Should we change the precision to lower resolution
  return ISO8601.parse(date).getTimeInMillis();
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons

/**
 * Constructs a <code>DateValue</code> object representing a date.
 *
 * @param date the date this <code>DateValue</code> should represent
 * @throws IllegalArgumentException if the given date cannot be represented
 * as defined by ISO 8601.
 */
public DateValue(Calendar date) throws IllegalArgumentException {
  super(TYPE);
  this.date = date;
  ISO8601.getYear(date);
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons

Calendar cal = Calendar.getInstance(tz);
cal.setLenient(false);
  cal.set(Calendar.YEAR, year + 1);
  cal.set(Calendar.ERA, GregorianCalendar.BC);
} else {
  getYear(cal);
} catch (IllegalArgumentException e) {
  return null;

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

/**
 * Converts individual java objects to JSONObjects using reflection and
 * recursion
 *
 * @param val an untyped Java object to try to convert
 * @return {@code val} if not handled, or return a converted JSONObject,
 * JSONArray, or String
 */
@SuppressWarnings({"unchecked", "squid:S3776"})
protected static Object convertValue(Object val) {
  if (val instanceof Calendar) {
    return ISO8601.format((Calendar) val);
  } else if (val instanceof Date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime((Date) val);
    return ISO8601.format(calendar);
  }
  return val;
}

代码示例来源:origin: apache/jackrabbit-oak

private static String now() {
  return ISO8601.format(Calendar.getInstance());
}

代码示例来源:origin: apache/jackrabbit-oak

public static Calendar getVersionHistoryLastModified(NodeState versionHistory) {
  Calendar youngest = Calendar.getInstance();
  youngest.setTimeInMillis(0);
  for (final ChildNodeEntry entry : versionHistory.getChildNodeEntries()) {
    final NodeState version = entry.getNodeState();
    if (version.hasProperty(JCR_CREATED)) {
      final Calendar created = ISO8601.parse(version.getProperty(JCR_CREATED).getValue(Type.DATE));
      if (created.after(youngest)) {
        youngest = created;
      }
    }
  }
  return youngest;
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons

appendZeroPaddedInt(buf, getYear(cal), 4);
buf.append('-');
appendZeroPaddedInt(buf, cal.get(Calendar.MONTH) + 1, 2);
buf.append('-');
appendZeroPaddedInt(buf, cal.get(Calendar.DAY_OF_MONTH), 2);
buf.append('T');
appendZeroPaddedInt(buf, cal.get(Calendar.HOUR_OF_DAY), 2);
buf.append(':');
appendZeroPaddedInt(buf, cal.get(Calendar.MINUTE), 2);
buf.append(':');
appendZeroPaddedInt(buf, cal.get(Calendar.SECOND), 2);
buf.append('.');
appendZeroPaddedInt(buf, cal.get(Calendar.MILLISECOND), 3);
  int minutes = Math.abs((offset / (60 * 1000)) % 60);
  buf.append(offset < 0 ? '-' : '+');
  appendZeroPaddedInt(buf, hours, 2);
  buf.append(':');
  appendZeroPaddedInt(buf, minutes, 2);
} else {
  buf.append('Z');

代码示例来源:origin: org.onehippo.cms7/hippo-addon-channel-manager-content-service

@Override
  protected FieldValue getFieldValue(final String value) {
    if (StringUtils.isBlank(value)) {
      return new FieldValue(StringUtils.EMPTY);
    }

    final Calendar calendar = ISO8601.parse(value);
    if (calendar == null || calendar.getTime().equals(PropertyValueProvider.EMPTY_DATE)) {
      return new FieldValue(StringUtils.EMPTY);
    }

    return new FieldValue(value);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * @return {@code false} if persisted lastUpdated time for index is after {@code calendar}. {@code true} otherwise
 */
private boolean isIndexUpdatedAfter(Calendar calendar) {
  NodeBuilder indexStats = definitionBuilder.child(":status");
  PropertyState indexLastUpdatedValue = indexStats.getProperty("lastUpdated");
  if (indexLastUpdatedValue != null) {
    Calendar indexLastUpdatedTime = ISO8601.parse(indexLastUpdatedValue.getValue(Type.DATE));
    return indexLastUpdatedTime.after(calendar);
  } else {
    return true;
  }
}

代码示例来源:origin: apache/tika

public String generateRSS(Path indexFile) throws CorruptIndexException,
    IOException {
  StringBuffer output = new StringBuffer();
  output.append(getRSSHeaders());
  IndexSearcher searcher = null;
  try {
    reader = DirectoryReader.open(FSDirectory.open(indexFile));
    searcher = new IndexSearcher(reader);
    GregorianCalendar gc = new java.util.GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
    gc.setTime(new Date());
    String nowDateTime = ISO8601.format(gc);
    gc.add(java.util.GregorianCalendar.MINUTE, -5);
    String fiveMinsAgo = ISO8601.format(gc);
    TermRangeQuery query = new TermRangeQuery(
        TikaCoreProperties.CREATED.getName(),
        new BytesRef(fiveMinsAgo), new BytesRef(nowDateTime),
        true, true);
    TopScoreDocCollector collector = TopScoreDocCollector.create(20);
    searcher.search(query, collector);
    ScoreDoc[] hits = collector.topDocs().scoreDocs;
    for (int i = 0; i < hits.length; i++) {
      Document doc = searcher.doc(hits[i].doc);
      output.append(getRSSItem(doc));
    }
  } finally {
    if (reader != null) reader.close();
  }
  output.append(getRSSFooters());
  return output.toString();
}

代码示例来源:origin: apache/tika

public String getRSSItem(Document doc) {
  StringBuilder output = new StringBuilder();
  output.append("<item>");
  output.append(emitTag("guid", doc.get(DublinCore.SOURCE.getName()),
      "isPermalink", "true"));
  output.append(emitTag("title", doc.get(TikaCoreProperties.TITLE.getName()), null, null));
  output.append(emitTag("link", doc.get(DublinCore.SOURCE.getName()),
      null, null));
  output.append(emitTag("author", doc.get(TikaCoreProperties.CREATOR.getName()), null, null));
  for (String topic : doc.getValues(TikaCoreProperties.SUBJECT.getName())) {
    output.append(emitTag("category", topic, null, null));
  }
  output.append(emitTag("pubDate", rssDateFormat.format(ISO8601.parse(doc
      .get(TikaCoreProperties.CREATED.getName()))), null, null));
  output.append(emitTag("description", doc.get(TikaCoreProperties.TITLE.getName()), null,
      null));
  output.append("</item>");
  return output.toString();
}

代码示例来源:origin: apache/jackrabbit

Calendar cal = Calendar.getInstance(tz);
cal.setLenient(false);
  cal.set(Calendar.YEAR, year + 1);
  cal.set(Calendar.ERA, GregorianCalendar.BC);
} else {
  getYear(cal);
} catch (IllegalArgumentException e) {
  return null;

代码示例来源:origin: io.wcm.tooling.commons/io.wcm.tooling.commons.content-package-builder

/**
 * @return Variables for placeholder replacement in package metadata.
 */
public Map<String, Object> getVars() {
 Calendar calendar = Calendar.getInstance();
 calendar.setTime(created);
 Map<String, Object> vars = new HashMap<>();
 vars.put(NAME_GROUP, StringUtils.defaultString(group));
 vars.put(NAME_NAME, StringUtils.defaultString(name));
 vars.put(NAME_DESCRIPTION, StringUtils.defaultString(description));
 vars.put(NAME_CREATED, ISO8601.format(calendar));
 vars.put(NAME_CREATED_BY, StringUtils.defaultString(createdBy));
 vars.put(NAME_VERSION, StringUtils.defaultString(version));
 vars.put(NAME_AC_HANDLING, acHandling != null ? acHandling.getMode() : "");
 vars.put("path", "/etc/packages/" + group + "/" + name + ".zip");
 vars.putAll(additionalProperties);
 return ImmutableMap.copyOf(vars);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private static String now() {
  return ISO8601.format(Calendar.getInstance());
}

代码示例来源:origin: org.apache.jackrabbit/oak-upgrade

public static Calendar getVersionHistoryLastModified(NodeState versionHistory) {
  Calendar youngest = Calendar.getInstance();
  youngest.setTimeInMillis(0);
  for (final ChildNodeEntry entry : versionHistory.getChildNodeEntries()) {
    final NodeState version = entry.getNodeState();
    if (version.hasProperty(JCR_CREATED)) {
      final Calendar created = ISO8601.parse(version.getProperty(JCR_CREATED).getValue(Type.DATE));
      if (created.after(youngest)) {
        youngest = created;
      }
    }
  }
  return youngest;
}

代码示例来源:origin: apache/jackrabbit

appendZeroPaddedInt(buf, getYear(cal), 4);
buf.append('-');
appendZeroPaddedInt(buf, cal.get(Calendar.MONTH) + 1, 2);
buf.append('-');
appendZeroPaddedInt(buf, cal.get(Calendar.DAY_OF_MONTH), 2);
buf.append('T');
appendZeroPaddedInt(buf, cal.get(Calendar.HOUR_OF_DAY), 2);
buf.append(':');
appendZeroPaddedInt(buf, cal.get(Calendar.MINUTE), 2);
buf.append(':');
appendZeroPaddedInt(buf, cal.get(Calendar.SECOND), 2);
buf.append('.');
appendZeroPaddedInt(buf, cal.get(Calendar.MILLISECOND), 3);
  int minutes = Math.abs((offset / (60 * 1000)) % 60);
  buf.append(offset < 0 ? '-' : '+');
  appendZeroPaddedInt(buf, hours, 2);
  buf.append(':');
  appendZeroPaddedInt(buf, minutes, 2);
} else {
  buf.append('Z');

代码示例来源:origin: org.apache.jackrabbit/oak-lucene

/**
 * @return {@code false} if persisted lastUpdated time for index is after {@code calendar}. {@code true} otherwise
 */
private boolean isIndexUpdatedAfter(Calendar calendar) {
  NodeBuilder indexStats = definitionBuilder.child(":status");
  PropertyState indexLastUpdatedValue = indexStats.getProperty("lastUpdated");
  if (indexLastUpdatedValue != null) {
    Calendar indexLastUpdatedTime = ISO8601.parse(indexLastUpdatedValue.getValue(Type.DATE));
    return indexLastUpdatedTime.after(calendar);
  } else {
    return true;
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.api

/**
 * @param input Calendar value
 * @return ISO8601 string representation or null
 */
public static String calendarToString(Calendar input) {
  if (input == null) {
    return null;
  }
  return ISO8601.format(input);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.resourceresolver-mock

/**
 * @param input ISO8601 string representation
 * @return Calendar value or null
 */
public static Calendar calendarFromString(String input) {
  if (input == null) {
    return null;
  }
  return ISO8601.parse(input);
}

相关文章