本文整理汇总了Java中org.joda.time.format.ISODateTimeFormat类的典型用法代码示例。如果您正苦于以下问题:Java ISODateTimeFormat类的具体用法?Java ISODateTimeFormat怎么用?Java ISODateTimeFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISODateTimeFormat类属于org.joda.time.format包,在下文中一共展示了ISODateTimeFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveExams
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SubjectNotPresent
public Result getActiveExams(Optional<String> date) {
PathProperties pp = PathProperties.parse("(course(name, code, credits, " +
"gradeScale(description, externalRef, displayName), organisation(code, name, nameAbbreviation)) " +
"name, examActiveStartDate, examActiveEndDate, duration, enrollInstruction, examLanguages(code, name) " +
"gradeScale(description, externalRef, displayName), examOwners(firstName, lastName, email), " +
"examType(type)" +
")");
DateTime dateTime = date.isPresent() ?
ISODateTimeFormat.dateTimeParser().parseDateTime(date.get()) :
DateTime.now();
Query<Exam> query = Ebean.find(Exam.class);
query.apply(pp);
List<Exam> exams = query.where()
.eq("state", Exam.State.PUBLISHED)
.lt("examActiveStartDate", dateTime)
.ge("examActiveEndDate", dateTime)
.eq("executionType.type", ExamExecutionType.Type.PUBLIC.toString())
.findList();
return ok(exams, pp);
}
示例2: getReservations
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SubjectNotPresent
public Result getReservations(Optional<String> start, Optional<String> end, Optional<Long> roomId) {
PathProperties pp = PathProperties.parse("(startAt, endAt, noShow, " +
"user(firstName, lastName, email, userIdentifier), " +
"enrolment(exam(name, examOwners(firstName, lastName, email), parent(examOwners(firstName, lastName, email)))), " +
"machine(name, ipAddress, otherIdentifier, room(name, roomCode)))");
Query<Reservation> query = Ebean.find(Reservation.class);
pp.apply(query);
ExpressionList<Reservation> el = query.where()
.isNotNull("enrolment")
.ne("enrolment.exam.state", Exam.State.DELETED);
if (start.isPresent()) {
DateTime startDate = ISODateTimeFormat.dateTimeParser().parseDateTime(start.get());
el = el.ge("startAt", startDate.toDate());
}
if (end.isPresent()) {
DateTime endDate = ISODateTimeFormat.dateTimeParser().parseDateTime(end.get());
el = el.lt("endAt", endDate.toDate());
}
if (roomId.isPresent()) {
el = el.eq("machine.room.id", roomId.get());
}
Set<Reservation> reservations = el.orderBy("startAt").findSet();
return ok(reservations, pp);
}
示例3: execute
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Override
public void execute(IngestDocument ingestDocument) {
String value = ingestDocument.getFieldValue(field, String.class);
DateTime dateTime = null;
Exception lastException = null;
for (Function<String, DateTime> dateParser : dateParsers) {
try {
dateTime = dateParser.apply(value);
} catch (Exception e) {
//try the next parser and keep track of the exceptions
lastException = ExceptionsHelper.useOrSuppress(lastException, e);
}
}
if (dateTime == null) {
throw new IllegalArgumentException("unable to parse date [" + value + "]", lastException);
}
ingestDocument.setFieldValue(targetField, ISODateTimeFormat.dateTime().print(dateTime));
}
示例4: testDateRangeInQueryString
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
public void testDateRangeInQueryString() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping(
"type", "past", "type=date", "future", "type=date"
));
String aMonthAgo = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).minusMonths(1));
String aMonthFromNow = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).plusMonths(1));
client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("future:[now/d TO now+2M/d]")).get();
assertHitCount(searchResponse, 1L);
SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch()
.setQuery(queryStringQuery("future:[now/D TO now+2M/d]").lenient(false)).get());
assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(e.toString(), containsString("unit [D] not supported for date math"));
}
示例5: testDateRangeInQueryStringWithTimeZone_7880
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
public void testDateRangeInQueryStringWithTimeZone_7880() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping(
"type", "past", "type=date"
));
DateTimeZone timeZone = randomDateTimeZone();
String now = ISODateTimeFormat.dateTime().print(new DateTime(timeZone));
logger.info(" --> Using time_zone [{}], now is [{}]", timeZone.getID(), now);
client().prepareIndex("test", "type", "1").setSource("past", now).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-1m/m TO now+1m/m]")
.timeZone(timeZone.getID())).get();
assertHitCount(searchResponse, 1L);
}
示例6: testExplainDateRangeInQueryString
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
public void testExplainDateRangeInQueryString() {
assertAcked(prepareCreate("test").setSettings(Settings.builder()
.put(indexSettings())
.put("index.number_of_shards", 1)));
String aMonthAgo = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).minusMonths(1));
String aMonthFromNow = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).plusMonths(1));
client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
refresh();
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery()
.setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).setRewrite(true).get();
assertNoFailures(response);
assertThat(response.getQueryExplanation().size(), equalTo(1));
assertThat(response.getQueryExplanation().get(0).getError(), nullValue());
DateTime twoMonthsAgo = new DateTime(DateTimeZone.UTC).minusMonths(2).withTimeAtStartOfDay();
DateTime now = new DateTime(DateTimeZone.UTC).plusDays(1).withTimeAtStartOfDay().minusMillis(1);
assertThat(response.getQueryExplanation().get(0).getExplanation(),
equalTo("past:[" + twoMonthsAgo.getMillis() + " TO " + now.getMillis() + "]"));
assertThat(response.isValid(), equalTo(true));
}
示例7: testDate
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
public void testDate() throws Exception {
assertResult("{'date':null}", () -> builder().startObject().field("date", (Date) null).endObject());
assertResult("{'date':null}", () -> builder().startObject().field("date").value((Date) null).endObject());
final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
assertResult("{'d1':'2016-01-01T00:00:00.000Z'}", () -> builder().startObject().field("d1", d1).endObject());
assertResult("{'d1':'2016-01-01T00:00:00.000Z'}", () -> builder().startObject().field("d1").value(d1).endObject());
final Date d2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC).toDate();
assertResult("{'d2':'2016-12-25T07:59:42.213Z'}", () -> builder().startObject().field("d2", d2).endObject());
assertResult("{'d2':'2016-12-25T07:59:42.213Z'}", () -> builder().startObject().field("d2").value(d2).endObject());
final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(), ISODateTimeFormat.dateTimeNoMillis());
final Date d3 = DateTime.now().toDate();
String expected = "{'d3':'" + formatter.print(d3.getTime()) + "'}";
assertResult(expected, () -> builder().startObject().field("d3", d3, formatter).endObject());
assertResult(expected, () -> builder().startObject().field("d3").value(d3, formatter).endObject());
expectNonNullFormatterException(() -> builder().startObject().field("d3", d3, null).endObject());
expectNonNullFormatterException(() -> builder().startObject().field("d3").value(d3, null).endObject());
expectNonNullFormatterException(() -> builder().value(null, 1L));
}
示例8: testDateRace
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Test
public void testDateRace() {
Clock mockClock = mock(Clock.class);
DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
long two = parser.parseMillis("2013-04-21T02:59:59-00:00");
long three = parser.parseMillis("2013-04-21T03:00:00-00:00");
when(mockClock.currentTimeMillis()).thenReturn(two, three);
// save & modify static state (yuck)
Clock origClock = BucketPath.getClock();
BucketPath.setClock(mockClock);
String pat = "%H:%M";
String escaped = BucketPath.escapeString(pat,
new HashMap<String, String>(),
TimeZone.getTimeZone("UTC"), true, Calendar.MINUTE, 10, true);
// restore static state
BucketPath.setClock(origClock);
Assert.assertEquals("Race condition detected", "02:50", escaped);
}
示例9: testRfc5424DateParsing
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Test
public void testRfc5424DateParsing() {
final String[] examples = {
"1985-04-12T23:20:50.52Z", "1985-04-12T19:20:50.52-04:00",
"2003-10-11T22:14:15.003Z", "2003-08-24T05:14:15.000003-07:00",
"2012-04-13T11:11:11-08:00", "2012-04-13T08:08:08.0001+00:00",
"2012-04-13T08:08:08.251+00:00"
};
SyslogParser parser = new SyslogParser();
DateTimeFormatter jodaParser = ISODateTimeFormat.dateTimeParser();
for (String ex : examples) {
Assert.assertEquals(
"Problem parsing date string: " + ex,
jodaParser.parseMillis(ex),
parser.parseRfc5424Date(ex));
}
}
示例10: writeTimestamp
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Override
public void writeTimestamp(boolean isNull) throws IOException {
TimeStampWriter ts = writer.timeStamp();
if(!isNull){
switch (parser.getCurrentToken()) {
case VALUE_NUMBER_INT:
DateTime dt = new DateTime(parser.getLongValue(), org.joda.time.DateTimeZone.UTC);
ts.writeTimeStamp(dt.getMillis());
break;
case VALUE_STRING:
DateTimeFormatter f = ISODateTimeFormat.dateTime();
ts.writeTimeStamp(DateTime.parse(parser.getValueAsString(), f).withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis());
break;
default:
throw UserException.unsupportedError()
.message(parser.getCurrentToken().toString())
.build(LOG);
}
}
}
示例11: BasicJsonOutput
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
protected BasicJsonOutput(JsonGenerator gen, DateOutputFormat dateOutput) {
Preconditions.checkNotNull(dateOutput);
Preconditions.checkNotNull(gen);
this.gen = gen;
switch (dateOutput) {
case SQL: {
dateFormatter = DateUtility.formatDate;
timeFormatter = DateUtility.formatTime;
timestampFormatter = DateUtility.formatTimeStamp;
break;
}
case ISO: {
dateFormatter = ISODateTimeFormat.date();
timeFormatter = ISODateTimeFormat.time();
timestampFormatter = ISODateTimeFormat.dateTime();
break;
}
default:
throw new UnsupportedOperationException(String.format("Unable to support date output of type %s.", dateOutput));
}
}
示例12: timelineStatus
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@RequestMapping("/timeline-status")
public List<TimelineValue> timelineStatus(@RequestParam(value = "link") String link) {
// formatter for use with json data
DateTimeFormatter df = ISODateTimeFormat.dateTime().withZoneUTC();
List<TimelineValue> timeline = new ArrayList<TimelineValue>();
List<Notification> notificationList = notificationRepo.findByEventOrderByTime(link);
extractChangeEvents(df, timeline, notificationList);
List<Link> links = linkRepo.findByName(link);
if (links != null && !links.isEmpty()) {
Link l = links.get(0);
List<Connection> connections = l.getConnections();
for (Connection c : connections) {
List<Notification> connNotList = notificationRepo.findByEventOrderByTime(c.getName());
extractChangeEvents(df, timeline, connNotList);
}
}
return timeline;
}
示例13: getRoomOpeningHours
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@SubjectNotPresent
public Result getRoomOpeningHours(Long roomId, Optional<String> date) {
if (!date.isPresent()) {
return badRequest("no search date given");
}
LocalDate searchDate = ISODateTimeFormat.dateParser().parseLocalDate(date.get());
PathProperties pp = PathProperties.parse("(*, defaultWorkingHours(*), calendarExceptionEvents(*))");
Query<ExamRoom> query = Ebean.find(ExamRoom.class);
pp.apply(query);
ExamRoom room = query.where().idEq(roomId).findUnique();
if (room == null) {
return notFound("room not found");
}
room.setCalendarExceptionEvents(room.getCalendarExceptionEvents().stream().filter(ee -> {
LocalDate start = new LocalDate(ee.getStartDate()).withDayOfMonth(1);
LocalDate end = new LocalDate(ee.getEndDate()).dayOfMonth().withMaximumValue();
return !start.isAfter(searchDate) && !end.isBefore(searchDate);
}).collect(Collectors.toList()));
return ok(room, pp);
}
示例14: applyFilters
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
private <T> ExpressionList<T> applyFilters(ExpressionList<T> query, String deptFieldPrefix, String dateField,
String dept, String start, String end) {
ExpressionList<T> result = query;
if (dept != null) {
String[] depts = dept.split(",");
result = result.in(String.format("%s.department", deptFieldPrefix), (Object[]) depts);
}
if (start != null) {
DateTime startDate = DateTime.parse(start, ISODateTimeFormat.dateTimeParser());
result = result.ge(dateField, startDate.toDate());
}
if (end != null) {
DateTime endDate = DateTime.parse(end, ISODateTimeFormat.dateTimeParser()).plusDays(1);
result = result.lt(dateField, endDate.toDate());
}
return result;
}
示例15: testCreateReservationStartIsPast
import org.joda.time.format.ISODateTimeFormat; //导入依赖的package包/类
@Test
@RunAsStudent
public void testCreateReservationStartIsPast() throws Exception {
// Setup
DateTime start = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).minusHours(1);
DateTime end = DateTime.now().withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).plusHours(2);
// Execute
Result result = request(Helpers.POST, "/app/calendar/reservation",
Json.newObject().put("roomId", room.getId())
.put("examId", exam.getId())
.put("start", ISODateTimeFormat.dateTime().print(start))
.put("end", ISODateTimeFormat.dateTime().print(end)));
assertThat(result.status()).isEqualTo(400);
// Verify
ExamEnrolment ee = Ebean.find(ExamEnrolment.class, enrolment.getId());
assertThat(ee.getReservation()).isNull();
}