本文整理匯總了Java中org.joda.time.chrono.ISOChronology.getInstanceUTC方法的典型用法代碼示例。如果您正苦於以下問題:Java ISOChronology.getInstanceUTC方法的具體用法?Java ISOChronology.getInstanceUTC怎麽用?Java ISOChronology.getInstanceUTC使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.chrono.ISOChronology
的用法示例。
在下文中一共展示了ISOChronology.getInstanceUTC方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRewriteDateToMatchAll
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testRewriteDateToMatchAll() throws IOException {
String fieldName = randomAsciiOfLengthBetween(1, 20);
RangeQueryBuilder query = new RangeQueryBuilder(fieldName) {
@Override
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException {
return Relation.WITHIN;
}
};
DateTime queryFromValue = new DateTime(2015, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
DateTime queryToValue = new DateTime(2016, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
query.from(queryFromValue);
query.to(queryToValue);
QueryShardContext queryShardContext = createShardContext();
QueryBuilder rewritten = query.rewrite(queryShardContext);
assertThat(rewritten, instanceOf(RangeQueryBuilder.class));
RangeQueryBuilder rewrittenRange = (RangeQueryBuilder) rewritten;
assertThat(rewrittenRange.fieldName(), equalTo(fieldName));
assertThat(rewrittenRange.from(), equalTo(null));
assertThat(rewrittenRange.to(), equalTo(null));
}
示例2: testRewriteDateToMatchAllWithTimezoneAndFormat
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testRewriteDateToMatchAllWithTimezoneAndFormat() throws IOException {
String fieldName = randomAsciiOfLengthBetween(1, 20);
RangeQueryBuilder query = new RangeQueryBuilder(fieldName) {
@Override
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException {
return Relation.WITHIN;
}
};
DateTime queryFromValue = new DateTime(2015, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
DateTime queryToValue = new DateTime(2016, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
query.from(queryFromValue);
query.to(queryToValue);
query.timeZone(randomFrom(DateTimeZone.getAvailableIDs()));
query.format("yyyy-MM-dd");
QueryShardContext queryShardContext = createShardContext();
QueryBuilder rewritten = query.rewrite(queryShardContext);
assertThat(rewritten, instanceOf(RangeQueryBuilder.class));
RangeQueryBuilder rewrittenRange = (RangeQueryBuilder) rewritten;
assertThat(rewrittenRange.fieldName(), equalTo(fieldName));
assertThat(rewrittenRange.from(), equalTo(null));
assertThat(rewrittenRange.to(), equalTo(null));
assertThat(rewrittenRange.timeZone(), equalTo(null));
assertThat(rewrittenRange.format(), equalTo(null));
}
示例3: testRewriteDateToMatchNone
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testRewriteDateToMatchNone() throws IOException {
String fieldName = randomAsciiOfLengthBetween(1, 20);
RangeQueryBuilder query = new RangeQueryBuilder(fieldName) {
@Override
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException {
return Relation.DISJOINT;
}
};
DateTime queryFromValue = new DateTime(2015, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
DateTime queryToValue = new DateTime(2016, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
query.from(queryFromValue);
query.to(queryToValue);
QueryShardContext queryShardContext = createShardContext();
QueryBuilder rewritten = query.rewrite(queryShardContext);
assertThat(rewritten, instanceOf(MatchNoneQueryBuilder.class));
}
示例4: testRewriteDateToSame
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testRewriteDateToSame() throws IOException {
String fieldName = randomAsciiOfLengthBetween(1, 20);
RangeQueryBuilder query = new RangeQueryBuilder(fieldName) {
@Override
protected MappedFieldType.Relation getRelation(QueryRewriteContext queryRewriteContext) throws IOException {
return Relation.INTERSECTS;
}
};
DateTime queryFromValue = new DateTime(2015, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
DateTime queryToValue = new DateTime(2016, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
query.from(queryFromValue);
query.to(queryToValue);
QueryShardContext queryShardContext = createShardContext();
QueryBuilder rewritten = query.rewrite(queryShardContext);
assertThat(rewritten, sameInstance(query));
}
示例5: fetchMetadata
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/** {@inheritDoc} */
protected byte[] fetchMetadata() throws MetadataProviderException {
try {
validateMetadataFile(metadataFile);
DateTime metadataUpdateTime = new DateTime(metadataFile.lastModified(), ISOChronology.getInstanceUTC());
if (getLastRefresh() == null || getLastUpdate() == null || metadataUpdateTime.isAfter(getLastRefresh())) {
return inputstreamToByteArray(new FileInputStream(metadataFile));
}
return null;
} catch (IOException e) {
String errMsg = "Unable to read metadata file " + metadataFile.getAbsolutePath();
log.error(errMsg, e);
throw new MetadataProviderException(errMsg, e);
}
}
示例6: doFilter
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/** {@inheritDoc} */
public void doFilter(XMLObject metadata) throws FilterException {
DateTime validUntil = getValidUntil(metadata);
if (validUntil == null) {
throw new FilterException("Metadata did not include a validUntil attribute");
}
DateTime now = new DateTime(ISOChronology.getInstanceUTC());
if (maxValidityInterval > 0 && validUntil.isAfter(now)) {
long validityInterval = validUntil.getMillis() - now.getMillis();
if (validityInterval > maxValidityInterval) {
throw new FilterException("Metadata's validity interval, " + validityInterval
+ "ms, is larger than is allowed, " + maxValidityInterval + "ms.");
}
}
}
示例7: standardPeriodIn
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/**
* Creates a new instance representing the number of complete standard length units
* in the specified period.
* <p>
* This factory method converts all fields from the period to hours using standardised
* durations for each field. Only those fields which have a precise duration in
* the ISO UTC chronology can be converted.
* <ul>
* <li>One week consists of 7 days.
* <li>One day consists of 24 hours.
* <li>One hour consists of 60 minutes.
* <li>One minute consists of 60 seconds.
* <li>One second consists of 1000 milliseconds.
* </ul>
* Months and Years are imprecise and periods containing these values cannot be converted.
*
* @param period the period to get the number of hours from, must not be null
* @param millisPerUnit the number of milliseconds in one standard unit of this period
* @throws IllegalArgumentException if the period contains imprecise duration values
*/
protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit) {
if (period == null) {
return 0;
}
Chronology iso = ISOChronology.getInstanceUTC();
long duration = 0L;
for (int i = 0; i < period.size(); i++) {
int value = period.getValue(i);
if (value != 0) {
DurationField field = period.getFieldType(i).getField(iso);
if (field.isPrecise() == false) {
throw new IllegalArgumentException(
"Cannot convert period to duration as " + field.getName() +
" is not precise in the period " + period);
}
duration = FieldUtils.safeAdd(duration, FieldUtils.safeMultiply(field.getUnitMillis(), value));
}
}
return FieldUtils.safeToInt(duration / millisPerUnit);
}
示例8: setInstant
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/**
* @param standardOffset standard offset just before instant
*/
public long setInstant(int year, int standardOffset, int saveMillis) {
int offset;
if (iMode == 'w') {
offset = standardOffset + saveMillis;
} else if (iMode == 's') {
offset = standardOffset;
} else {
offset = 0;
}
Chronology chrono = ISOChronology.getInstanceUTC();
long millis = chrono.year().set(0, year);
millis = chrono.monthOfYear().set(millis, iMonthOfYear);
millis = chrono.millisOfDay().set(millis, iMillisOfDay);
millis = setDayOfMonth(chrono, millis);
if (iDayOfWeek != 0) {
millis = setDayOfWeek(chrono, millis);
}
// Convert from local time to UTC.
return millis - offset;
}
示例9: parseInstant
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public static long parseInstant(String input, long now) {
if (input.charAt(0) == '+') {
return now + Long.parseLong(input.substring(1));
}
if (input.charAt(0) == '-') {
return now - Long.parseLong(input.substring(1));
}
// try to parse just milliseconds
try {
return Long.parseLong(input);
} catch (IllegalArgumentException e) {
// pass-through
}
final Chronology chrono = ISOChronology.getInstanceUTC();
if (input.indexOf('/') >= 0) {
return parseFullInstant(input, chrono);
}
return parseTodayInstant(input, chrono, now);
}
示例10: setUp
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/** {@inheritDoc} */
protected void setUp() throws Exception {
super.setUp();
expectedID = "def456";
expectedInResponseTo = "abc123";
expectedSAMLVersion = SAMLVersion.VERSION_20;
expectedIssueInstant = new DateTime(2006, 2, 21, 16, 40, 0, 0, ISOChronology.getInstanceUTC());
expectedDestination = "http://sp.example.org/endpoint";
expectedConsent = "urn:string:consent";
QName issuerQName = new QName(SAMLConstants.SAML20_NS, Issuer.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
expectedIssuer = (Issuer) buildXMLObject(issuerQName);
QName statusQName = new QName(SAMLConstants.SAML20P_NS, Status.DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20P_PREFIX);
expectedStatus = (Status) buildXMLObject(statusQName);
}
示例11: testConstructor_Object_Chronology2
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testConstructor_Object_Chronology2() throws Throwable {
long length =
(4L + (3L * 7L) + (2L * 30L) + 365L) * DateTimeConstants.MILLIS_PER_DAY +
5L * DateTimeConstants.MILLIS_PER_HOUR +
6L * DateTimeConstants.MILLIS_PER_MINUTE +
7L * DateTimeConstants.MILLIS_PER_SECOND + 8L;
MutablePeriod test = new MutablePeriod(new Duration(length), ISOChronology.getInstanceUTC());
assertEquals(PeriodType.standard(), test.getPeriodType());
assertEquals(0, test.getYears()); // (4 + (3 * 7) + (2 * 30) + 365) == 450
assertEquals(0, test.getMonths());
assertEquals(64, test.getWeeks());
assertEquals(2, test.getDays());
assertEquals(5, test.getHours());
assertEquals(6, test.getMinutes());
assertEquals(7, test.getSeconds());
assertEquals(8, test.getMillis());
}
示例12: testConstructor_long_PeriodType_Chronology2
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testConstructor_long_PeriodType_Chronology2() throws Throwable {
long length = 4 * DateTimeConstants.MILLIS_PER_DAY +
5 * DateTimeConstants.MILLIS_PER_HOUR +
6 * DateTimeConstants.MILLIS_PER_MINUTE +
7 * DateTimeConstants.MILLIS_PER_SECOND + 8;
Period test = new Period(length, PeriodType.standard(), ISOChronology.getInstanceUTC());
assertEquals(PeriodType.standard(), test.getPeriodType());
assertEquals(0, test.getYears());
assertEquals(0, test.getMonths());
assertEquals(0, test.getWeeks());
assertEquals(4, test.getDays());
assertEquals(5, test.getHours());
assertEquals(6, test.getMinutes());
assertEquals(7, test.getSeconds());
assertEquals(8, test.getMillis());
}
示例13: testEqualsHashCode_ISO
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testEqualsHashCode_ISO() {
Chronology chrono1 = ISOChronology.getInstanceUTC();
Chronology chrono2 = ISOChronology.getInstanceUTC();
Chronology chrono3 = ISOChronology.getInstance();
assertEquals(true, chrono1.equals(chrono2));
assertEquals(false, chrono1.equals(chrono3));
DateTime dt1 = new DateTime(0L, chrono1);
DateTime dt2 = new DateTime(0L, chrono2);
DateTime dt3 = new DateTime(0L, chrono3);
assertEquals(true, dt1.equals(dt2));
assertEquals(false, dt1.equals(dt3));
assertEquals(true, chrono1.hashCode() == chrono2.hashCode());
assertEquals(false, chrono1.hashCode() == chrono3.hashCode());
}
示例14: refresh
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
/**
* Refreshes the metadata from its source.
*
* @throws ResolverException thrown is there is a problem retrieving and processing the metadata
*/
public synchronized void refresh() throws ResolverException {
final DateTime now = new DateTime(ISOChronology.getInstanceUTC());
final String mdId = getMetadataIdentifier();
long refreshDelay = 0;
log.debug("Beginning refresh of metadata from '{}'", mdId);
try {
byte[] mdBytes = fetchMetadata();
if (mdBytes == null) {
log.debug("Metadata from '{}' has not changed since last refresh", mdId);
} else {
log.debug("Processing new metadata from '{}'", mdId);
final Value information = parse(mdBytes);
final Key id = getKey(information);
log.info("Parsed entity information for {}", id);
final JsonBackingStore newBackingStore = new JsonBackingStore();
List<Value> allInformation = new ArrayList<>();
allInformation.add(information);
newBackingStore.getIndexedInformation().put(id, allInformation);
newBackingStore.getOrderedInformation().add(information);
setBackingStore(newBackingStore);
lastUpdate = now;
}
} catch (Throwable t) {
log.error("Error occurred while attempting to refresh metadata from '" + mdId + "'", t);
refreshDelay = minRefreshDelay;
if (t instanceof Exception) {
throw new ResolverException((Exception) t);
} else {
throw new ResolverException(String.format("Saw an error of type '%s' with message '%s'",
t.getClass().getName(), t.getMessage()));
}
} finally {
scheduleNextRefresh(refreshDelay);
lastRefresh = now;
}
}
開發者ID:CSCfi,項目名稱:shibboleth-idp-oidc-extension,代碼行數:44,代碼來源:AbstractReloadingOIDCEntityResolver.java
示例15: testHighlightQueryRewriteDatesWithNow
import org.joda.time.chrono.ISOChronology; //導入方法依賴的package包/類
public void testHighlightQueryRewriteDatesWithNow() throws Exception {
assertAcked(client().admin().indices().prepareCreate("index-1").addMapping("type", "d", "type=date",
"field", "type=text,store=true,term_vector=with_positions_offsets")
.setSettings("index.number_of_replicas", 0, "index.number_of_shards", 2)
.get());
DateTime now = new DateTime(ISOChronology.getInstanceUTC());
indexRandom(true, client().prepareIndex("index-1", "type", "1").setSource("d", now, "field", "hello world"),
client().prepareIndex("index-1", "type", "2").setSource("d", now.minusDays(1), "field", "hello"),
client().prepareIndex("index-1", "type", "3").setSource("d", now.minusDays(2), "field", "world"));
ensureSearchable("index-1");
for (int i = 0; i < 5; i++) {
final SearchResponse r1 = client().prepareSearch("index-1")
.addSort("d", SortOrder.DESC)
.setTrackScores(true)
.highlighter(highlight()
.field("field")
.preTags("<x>")
.postTags("</x>")
).setQuery(QueryBuilders.boolQuery().must(
QueryBuilders.rangeQuery("d").gte("now-12h").lte("now").includeLower(true).includeUpper(true).boost(1.0f))
.should(QueryBuilders.termQuery("field", "hello")))
.get();
assertSearchResponse(r1);
assertThat(r1.getHits().getTotalHits(), equalTo(1L));
assertHighlight(r1, 0, "field", 0, 1,
equalTo("<x>hello</x> world"));
}
}