org.joda.time.DateMidnight Java Examples
The following examples show how to use
org.joda.time.DateMidnight.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChronoConvertlets.java From dremio-oss with Apache License 2.0 | 6 votes |
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { final int timeZoneIndex = getContextInformation().getRootFragmentTimeZone(); final DateTimeZone timeZone = DateTimeZone.forID(JodaDateUtility.getTimeZone(timeZoneIndex)); final LocalDateTime dateTime = new LocalDateTime(getContextInformation().getQueryStartTime(), timeZone); final long midNightAsMillis = new DateMidnight(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), timeZone) .withZoneRetainFields(DateTimeZone.UTC) .getMillis(); return cx.getRexBuilder() .makeDateLiteral(DateTimes.toDateTime( new LocalDateTime(midNightAsMillis, DateTimeZone.UTC)) .toCalendar(null)); // null sets locale to default locale }
Example #2
Source File: WeeklyWorkLoadDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public CurricularYearWeeklyWorkLoadView(final DegreeCurricularPlan degreeCurricularPlan, final ExecutionSemester executionSemester, final Set<ExecutionCourse> executionCourses) { final ExecutionDegree executionDegree = findExecutionDegree(executionSemester, degreeCurricularPlan); if (executionDegree != null) { this.interval = new Interval(new DateMidnight(getBegginingOfLessonPeriod(executionSemester, executionDegree)), new DateMidnight(getEndOfExamsPeriod(executionSemester, executionDegree))); final Period period = interval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = interval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } this.executionCourses.addAll(executionCourses); } }
Example #3
Source File: CalendarPanel.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
/** * @see org.projectforge.web.wicket.AbstractSecuredPage#onBeforeRender() */ @Override protected void onBeforeRender() { super.onBeforeRender(); // Restore current date (e. g. on reload or on coming back from callee page). final MyFullCalendarConfig config = calendar.getConfig(); final DateMidnight startDate = filter.getStartDate(); if (startDate != null) { config.setYear(startDate.getYear()); config.setMonth(startDate.getMonthOfYear() - 1); config.setDate(startDate.getDayOfMonth()); } config.setDefaultView(filter.getViewType().getCode()); if (refresh == true) { refresh = false; timesheetEventsProvider.forceReload(); birthdayEventsProvider.forceReload(); hrPlanningEventsProvider.forceReload(); setConfig(); onRefreshEventProvider(); } }
Example #4
Source File: StreamServiceUnitTest.java From btrbck with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @Test public void testIsSnapshotRequired() throws Exception { StreamService service = new StreamService(); Period period = Period.days(2); Collection<Snapshot> snapshots = new ArrayList<>(); snapshots.add(new Snapshot(0, new DateTime(2014, 1, 1, 0, 0), null)); snapshots.add(new Snapshot(0, new DateTime(2014, 1, 2, 0, 0), null)); snapshots.add(new Snapshot(0, new DateTime(2014, 1, 3, 0, 0), null)); assertThat(service.isSnapshotRequired( new DateMidnight(2014, 1, 3).toInstant(), period, snapshots), is(false)); assertThat(service.isSnapshotRequired( new DateMidnight(2014, 1, 4).toInstant(), period, snapshots), is(false)); assertThat(service.isSnapshotRequired( new DateMidnight(2014, 1, 5).toInstant(), period, snapshots), is(true)); }
Example #5
Source File: ViewDisplayCallback.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Override protected void respond(final AjaxRequestTarget target) { final Request r = target.getPage().getRequest(); final ViewType type = ViewType.forCode(r.getRequestParameters().getParameterValue("view").toString()); final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withZone(PFUserContext.getDateTimeZone()); final DateMidnight start = fmt.parseDateTime(r.getRequestParameters().getParameterValue("start").toString()) .toDateMidnight(); final DateMidnight end = fmt.parseDateTime(r.getRequestParameters().getParameterValue("end").toString()) .toDateMidnight(); final DateMidnight visibleStart = fmt.parseDateTime( r.getRequestParameters().getParameterValue("visibleStart").toString()).toDateMidnight(); final DateMidnight visibleEnd = fmt .parseDateTime(r.getRequestParameters().getParameterValue("visibleEnd").toString()).toDateMidnight(); final View view = new View(type, start, end, visibleStart, visibleEnd); final CalendarResponse response = new CalendarResponse(getCalendar(), target); onViewDisplayed(view, response); }
Example #6
Source File: JodaDateConverterTest.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
@Test public void convertToString() { final PFUserDO user = new PFUserDO(); user.setTimeZone(DateHelper.EUROPE_BERLIN); user.setLocale(Locale.GERMAN); user.setDateFormat("dd.MM.yyyy"); PFUserContext.setUser(user); JodaDateConverter conv = new JodaDateConverter(); DateMidnight testDate = createDate(1970, DateTimeConstants.NOVEMBER, 21, EUROPE_BERLIN); assertEquals("21.11.1970", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.ENGLISH); user.setDateFormat("MM/dd/yyyy"); conv = new JodaDateConverter(); assertEquals("11/21/1970", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.GERMAN); user.setDateFormat("dd.MM.yyyy"); conv = new JodaDateConverter(); testDate = createDate(2009, DateTimeConstants.FEBRUARY, 1, EUROPE_BERLIN); assertEquals("01.02.2009", conv.convertToString(testDate, Locale.GERMAN)); user.setLocale(Locale.ENGLISH); user.setDateFormat("MM/dd/yyyy"); conv = new JodaDateConverter(); assertEquals("02/01/2009", conv.convertToString(testDate, Locale.GERMAN)); }
Example #7
Source File: TestConverterSet.java From astor with GNU General Public License v2.0 | 6 votes |
public void testBigHashtable() { Converter[] array = new Converter[] { c1, c2, c3, c4, }; ConverterSet set = new ConverterSet(array); set.select(Boolean.class); set.select(Character.class); set.select(Byte.class); set.select(Short.class); set.select(Integer.class); set.select(Long.class); set.select(Float.class); set.select(Double.class); set.select(null); set.select(Calendar.class); set.select(GregorianCalendar.class); set.select(DateTime.class); set.select(DateMidnight.class); set.select(ReadableInstant.class); set.select(ReadableDateTime.class); set.select(ReadWritableInstant.class); // 16 set.select(ReadWritableDateTime.class); set.select(DateTime.class); assertEquals(4, set.size()); }
Example #8
Source File: TestConverterSet.java From astor with GNU General Public License v2.0 | 6 votes |
public void testBigHashtable() { Converter[] array = new Converter[] { c1, c2, c3, c4, }; ConverterSet set = new ConverterSet(array); set.select(Boolean.class); set.select(Character.class); set.select(Byte.class); set.select(Short.class); set.select(Integer.class); set.select(Long.class); set.select(Float.class); set.select(Double.class); set.select(null); set.select(Calendar.class); set.select(GregorianCalendar.class); set.select(DateTime.class); set.select(DateMidnight.class); set.select(ReadableInstant.class); set.select(ReadableDateTime.class); set.select(ReadWritableInstant.class); // 16 set.select(ReadWritableDateTime.class); set.select(DateTime.class); assertEquals(4, set.size()); }
Example #9
Source File: AutomaticAdapterSelector.java From Carbonado with Apache License 2.0 | 6 votes |
/** * @param property bean property which must have a read method * @return adapter with a null annotation, or null if nothing applicable */ static StorablePropertyAdapter selectAdapterFor(final BeanProperty property) { final Method readMethod = property.getReadMethod(); if (readMethod == null) { throw new IllegalArgumentException(); } final Class propertyType = property.getType(); if (DateTime.class.isAssignableFrom(propertyType) || DateMidnight.class.isAssignableFrom(propertyType) || LocalDate.class.isAssignableFrom(propertyType) || LocalDateTime.class.isAssignableFrom(propertyType) || java.util.Date.class.isAssignableFrom(propertyType)) { return selectAdapter(property, DateTimeAdapter.class, readMethod); } else if (String.class.isAssignableFrom(propertyType)) { return selectAdapter(property, TextAdapter.class, readMethod); } // else if ... return null; }
Example #10
Source File: JodaDateMidnightConverter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
Object parse(final String data) { try { final DateTimeFormatter parseFormat = DateTimeFormat.forPattern(ISO_FORMAT); final DateTime date = parseFormat.withZone(DateTimeZone.UTC).parseDateTime(data); final DateMidnight dateMidnight = date.toDateMidnight(); return dateMidnight; } catch (final Exception ex) { log.error("Can't parse DateMidnight: " + data); return new DateMidnight(); } }
Example #11
Source File: PersistenceExtensionsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testMaximumSince() { item.setState(new DecimalType(1)); HistoricItem historicItem = PersistenceExtensions.maximumSince(item, new DateMidnight(2012, 1, 1), "test"); assertNotNull(historicItem); assertEquals("1", historicItem.getState().toString()); historicItem = PersistenceExtensions.maximumSince(item, new DateMidnight(2005, 1, 1), "test"); assertEquals("2012", historicItem.getState().toString()); assertEquals(new DateMidnight(2012, 1, 1).toDate(), historicItem.getTimestamp()); }
Example #12
Source File: PersistenceExtensionsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testHistoricState() { HistoricItem historicItem = PersistenceExtensions.historicState(item, new DateMidnight(2012, 1, 1), "test"); assertEquals("2012", historicItem.getState().toString()); historicItem = PersistenceExtensions.historicState(item, new DateMidnight(2011, 12, 31), "test"); assertEquals("2011", historicItem.getState().toString()); historicItem = PersistenceExtensions.historicState(item, new DateMidnight(2011, 1, 1), "test"); assertEquals("2011", historicItem.getState().toString()); historicItem = PersistenceExtensions.historicState(item, new DateMidnight(2000, 1, 1), "test"); assertEquals("2000", historicItem.getState().toString()); }
Example #13
Source File: Attends.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public Interval getResponseWeek() { final DateMidnight beginningOfSemester = new DateMidnight(getBegginingOfLessonPeriod()); final DateMidnight firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight secondMonday = firstMonday.plusWeeks(1); final DateMidnight endOfSemester = new DateMidnight(getEndOfExamsPeriod()); final DateMidnight lastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight endOfResponsePeriod = lastMonday.plusWeeks(2); return (secondMonday.isEqualNow() || secondMonday.isBeforeNow()) && endOfResponsePeriod.isAfterNow() ? getPreviousWeek() : null; }
Example #14
Source File: Attends.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public int calculateCurrentWeekOffset() { final DateMidnight beginningOfLessonPeriod = new DateMidnight(getBegginingOfLessonPeriod()); final DateMidnight firstMonday = beginningOfLessonPeriod.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight thisMonday = new DateMidnight().withField(DateTimeFieldType.dayOfWeek(), 1); final Interval interval = new Interval(firstMonday, thisMonday); return interval.toPeriod(PeriodType.weeks()).getWeeks(); }
Example #15
Source File: ExecutionSemester.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public DateMidnight getThisMonday() { final DateTime beginningOfSemester = getBeginDateYearMonthDay().toDateTimeAtMidnight(); final DateTime endOfSemester = getEndDateYearMonthDay().toDateTimeAtMidnight(); if (beginningOfSemester.isAfterNow() || endOfSemester.isBeforeNow()) { return null; } final DateMidnight now = new DateMidnight(); return now.withField(DateTimeFieldType.dayOfWeek(), 1); }
Example #16
Source File: JodaTimeExampleTest.java From snake-yaml with Apache License 2.0 | 5 votes |
/** * test issue 109 */ public void test109() { Date someDate = new DateMidnight(9, 2, 21, DateTimeZone.forID("Europe/Amsterdam")).toDate(); Yaml yaml = new Yaml(); String timestamp = yaml.dump(someDate); assertEquals("0009-02-22T23:40:28Z\n", timestamp); // System.out.println(timestamp); Object o = yaml.load(timestamp); assertEquals(someDate, o); }
Example #17
Source File: ConvertersTest.java From gson-jodatime-serialisers with MIT License | 5 votes |
/** * Tests that the {@link Converters#registerAll} method registers the converters successfully. */ @Test public void testRegisterAll() { final Gson gson = Converters.registerAll(new GsonBuilder()).create(); final Container original = new Container(); //noinspection deprecation original.dm = new DateMidnight(); original.dt = new DateTime(); original.dtz = DateTimeZone.forID("UTC"); original.d = Duration.standardMinutes(30L); original.ld = new LocalDate(); original.ldt = new LocalDateTime(); original.lt = new LocalTime(); original.i = new Interval(DateTime.now().minusDays(14), DateTime.now().plusDays(2)); original.p = Period.days(2); final Container reconstituted = gson.fromJson(gson.toJson(original), Container.class); assertThat(reconstituted.dm, is(original.dm)); assertThat(reconstituted.dt.toString(), is(original.dt.toString())); // work-around the loss of zone name and just worry about the offset assertThat(reconstituted.dtz, is(original.dtz)); assertThat(reconstituted.d, is(original.d)); assertThat(reconstituted.ld, is(original.ld)); assertThat(reconstituted.ldt, is(original.ldt)); assertThat(reconstituted.lt, is(original.lt)); assertThat(reconstituted.i, is(original.i)); assertThat(reconstituted.p, is(original.p)); }
Example #18
Source File: AbstractCalendarFilter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @param startDate the startDate to set * @return this for chaining. */ public AbstractCalendarFilter setStartDate(final DateMidnight startDate) { if (startDate != null) { this.startDate = startDate; } else { this.startDate = new DateMidnight(); } return this; }
Example #19
Source File: JodaDateConverter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @param locale ignored, locale of PFUserContext is used instead. * @see org.apache.wicket.datetime.DateConverter#convertToString(java.lang.Object, java.util.Locale) * @see DateTimeFormatter#getFormattedDate(Object) */ @Override public String convertToString(final DateMidnight value, final Locale locale) { if (value == null) { return null; } final DateTimeFormatter formatter = getDateTimeFormatter(userDateFormat, locale); return formatter.print(value); }
Example #20
Source File: JodaDateConverter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * Attempts to convert a String to a Date object. Pre-processes the input by invoking the method preProcessInput(), then uses an ordered * list of DateFormat objects (supplied by getDateFormats()) to try and parse the String into a Date. */ @Override public DateMidnight convertToObject(final String value, final Locale locale) { if (StringUtils.isBlank(value) == true) { return null; } final String[] formatStrings = getFormatStrings(locale); final DateTimeFormatter[] dateFormats = new DateTimeFormatter[formatStrings.length]; for (int i = 0; i < formatStrings.length; i++) { dateFormats[i] = getDateTimeFormatter(formatStrings[i], locale); } DateMidnight date = null; for (final DateTimeFormatter formatter : dateFormats) { try { date = DateMidnight.parse(value, formatter); break; } catch (final Exception ex) { /* Do nothing, we'll get lots of these. */ if (log.isDebugEnabled() == true) { log.debug(ex.getMessage(), ex); } } } // If we successfully parsed, return a date, otherwise send back an error if (date != null) { return date; } else { log.info("Unparseable date string (user's input): " + value); throw new ConversionException("validation.error.general"); // Message key will not be used (dummy). } }
Example #21
Source File: JodaDatePanel.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * @param id * @param label Only for displaying the field's name on validation messages. * @param model */ public JodaDatePanel(final String id, final IModel<DateMidnight> model) { super(id); dateField = new JodaDateField("dateField", model); dateField.add(AttributeModifier.replace("size", "10")); dateField.setOutputMarkupId(true); add(dateField); }
Example #22
Source File: JodaDateMidnightConverter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("rawtypes") public boolean canConvert(final Class clazz) { if (DateMidnight.class.isAssignableFrom(clazz) == true) { return true; } return false; }
Example #23
Source File: JodaDateTimeConverter.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
Object parse(final String data) { try { final DateTimeFormatter parseFormat = DateTimeFormat.forPattern(ISO_FORMAT); final DateTime date = parseFormat.withZone(DateTimeZone.UTC).parseDateTime(data); final DateTimeZone dateTimeZone = PFUserContext.getDateTimeZone(); return new DateTime(date, dateTimeZone); } catch (final Exception ex) { log.error("Can't parse DateMidnight: " + data); return new DateMidnight(); } }
Example #24
Source File: DateMidnightConverterTest.java From gson-jodatime-serialisers with MIT License | 5 votes |
/** * Tests that deserialising a null string returns null */ @Test public void testDeserialiseNullString() { final Gson gson = Converters.registerDateMidnight(new GsonBuilder()).create(); assertThat(gson.fromJson((String) null, DateMidnight.class), is(nullValue())); }
Example #25
Source File: View.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
public View(ViewType type, DateMidnight start, DateMidnight end, DateMidnight visibleStart, DateMidnight visibleEnd) { this.type = type; this.start = start; this.end = end; this.visibleStart = visibleStart; this.visibleEnd = visibleEnd; }
Example #26
Source File: DateMidnightConverterTest.java From gson-jodatime-serialisers with MIT License | 5 votes |
/** * Tests that deserialising an empty string returns null */ @Test public void testDeserialiseEmptyString() { final Gson gson = Converters.registerDateMidnight(new GsonBuilder()).create(); assertThat(gson.fromJson("", DateMidnight.class), is(nullValue())); }
Example #27
Source File: JodaDateConverterTest.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
private void convertToObjectEnglish(final DateTimeZone timeZone) { final PFUserDO user = new PFUserDO(); user.setTimeZone(timeZone.getID()); PFUserContext.setUser(user); final JodaDateConverter conv = new JodaDateConverter(); DateMidnight testDate = createDate(1970, DateTimeConstants.OCTOBER, 21, timeZone); DateMidnight date = conv.convertToObject("10/21/1970", Locale.ENGLISH); assertDates(testDate, date); date = conv.convertToObject("10/21/70", Locale.ENGLISH); assertDates(testDate, date); date = conv.convertToObject("1970-10-21", Locale.ENGLISH); assertDates(testDate, date); try { date = conv.convertToObject(String.valueOf(testDate), Locale.ENGLISH); // millis not supported. fail("ConversionException exprected."); } catch (final ConversionException ex) { // OK } final Calendar cal = Calendar.getInstance(); final int year = cal.get(Calendar.YEAR); testDate = createDate(year, DateTimeConstants.OCTOBER, 21, timeZone); date = conv.convertToObject("10/21", Locale.ENGLISH); assertDates(testDate, date); }
Example #28
Source File: JodaDateConverterTest.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
private void assertDates(final DateMidnight expected, final DateMidnight actual) { assertEquals(expected.getYear(), actual.getYear()); assertEquals(expected.getMonthOfYear(), actual.getMonthOfYear()); assertEquals(expected.getDayOfMonth(), actual.getDayOfMonth()); assertEquals(expected.getHourOfDay(), actual.getHourOfDay()); assertEquals(expected.getMinuteOfHour(), actual.getMinuteOfHour()); assertEquals(expected.getSecondOfMinute(), actual.getSecondOfMinute()); assertEquals(expected.getMillisOfSecond(), actual.getMillisOfSecond()); }
Example #29
Source File: DateMidnightConverterTest.java From gson-jodatime-serialisers with MIT License | 5 votes |
/** * Tests that the {@link DateMidnight} can be round-tripped. */ @Test public void testRoundtrip() { final Gson gson = Converters.registerDateMidnight(new GsonBuilder()).create(); final DateMidnight dm = new DateMidnight(); assertThat(gson.fromJson(gson.toJson(dm), DateMidnight.class), is(dm)); }
Example #30
Source File: JodaDateMidnightConverterTest.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
private void test(final TimeZone timeZone) { final PFUserDO user = new PFUserDO(); user.setTimeZone(timeZone); PFUserContext.setUser(user); final JodaDateMidnightConverter converter = new JodaDateMidnightConverter(); final DateMidnight dateMidnight = (DateMidnight) converter.parse("1970-11-21"); Assert.assertEquals(1970, dateMidnight.getYear()); Assert.assertEquals(11, dateMidnight.getMonthOfYear()); Assert.assertEquals(21, dateMidnight.getDayOfMonth()); Assert.assertEquals("1970-11-21", converter.toString(dateMidnight)); }