org.joda.time.MonthDay Java Examples

The following examples show how to use org.joda.time.MonthDay. 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: DateUnknownYear.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the anniversary date not yet passed (with delta of 1 day)
 * @param date Date
 * @return Next anniversary in the year
 */
public static Date getNextAnniversary(Date date) {
    DateTime dateTimeNow = DateTime.now();
    MonthDay monthDayNow = MonthDay.now();
    MonthDay monthDayOfNextDate = MonthDay.fromDateFields(date);
    if(monthDayNow.isEqual(monthDayOfNextDate)) {
        DateTime inputDate = new DateTime(date);
        return dateTimeNow
                .withHourOfDay(inputDate.getHourOfDay())
                .withMinuteOfHour(inputDate.getMinuteOfHour())
                .withSecondOfMinute(inputDate.getSecondOfMinute())
                .withMillisOfSecond(inputDate.getMillisOfSecond()).toDate();
    } if(monthDayNow.isBefore(monthDayOfNextDate))
        return new DateTime(date).withYear(dateTimeNow.getYear()).toDate();
    else {
        DateTime dateTimeOfNextDate = new DateTime(date).withYear(dateTimeNow.getYear()).plusYears(1);
        return dateTimeOfNextDate.toDate();
    }
}
 
Example #2
Source File: TestAllClassDataTypesAreSupported.java    From jfixture with MIT License 5 votes vote down vote up
@Test
public void creates_instance_of_MonthDay() {
    MonthDay monthDay = fixture.create(MonthDay.class);
    assertThat(monthDay, notNullValue());
    assertThat(monthDay.getMonthOfYear(), is(1));
    assertThat(monthDay.getDayOfMonth(), is(1));
}
 
Example #3
Source File: DateUnknownYear.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return number of days between today and the next date in a year
 * @param date date for calculate delta
 * @return Number of days always >= 0
 */
public static int daysBetweenTodayAnd(Date date) {
    MonthDay monthDayNow = MonthDay.now();
    MonthDay monthDayOfNextDate = MonthDay.fromDateFields(date);
    if(monthDayNow.isEqual(monthDayOfNextDate))
        return 0;
    if(monthDayNow.isBefore(monthDayOfNextDate))
        return Days.daysBetween(monthDayNow, monthDayOfNextDate).getDays();
    else {
        DateTime dateTimeNow = DateTime.now();
        DateTime dateTimeOfNextDate = new DateTime(date).withYear(dateTimeNow.getYear()).plusYears(1);
        return Days.daysBetween(DateTime.now(), dateTimeOfNextDate).getDays();
    }
}
 
Example #4
Source File: JodaTimeFormatterRegistrar.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static void registerAdditionalFormatters(FormatterRegistry registry) {
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
 
Example #5
Source File: MonthDayAsStringHolder.java    From jadira with Apache License 2.0 4 votes vote down vote up
public void setMonthDay(MonthDay monthDay) {
    this.monthDay = monthDay;
}
 
Example #6
Source File: MonthDayAsStringHolder.java    From jadira with Apache License 2.0 4 votes vote down vote up
public MonthDay getMonthDay() {
    return monthDay;
}
 
Example #7
Source File: StringColumnMonthDayMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullValue(MonthDay value) {
    return value.toString();
}
 
Example #8
Source File: StringColumnMonthDayMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public MonthDay fromNonNullValue(String s) {
    return MonthDay.parse(s);
}
 
Example #9
Source File: JodaTimeFormattingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
Example #10
Source File: JodaTimeFormattingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public MonthDay getMonthDay() {
	return monthDay;
}
 
Example #11
Source File: JodaTimeFormatterRegistrar.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public static void registerAdditionalFormatters(FormatterRegistry registry) {
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
 
Example #12
Source File: MonthDayFormatter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
Example #13
Source File: MonthDayFormatter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
Example #14
Source File: MonthDayFormatter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
Example #15
Source File: MonthDayFormatter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
Example #16
Source File: MonthDayFormatter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
Example #17
Source File: JodaTimeFormattingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
Example #18
Source File: JodaTimeFormattingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
public MonthDay getMonthDay() {
	return monthDay;
}
 
Example #19
Source File: JodaTimeFormatterRegistrar.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	JodaTimeConverters.registerConverters(registry);

	DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
	DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
	DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateFormatter),
			new LocalDateParser(dateFormatter),
			LocalDate.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(timeFormatter),
			new LocalTimeParser(timeFormatter),
			LocalTime.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateTimeFormatter),
			new LocalDateTimeParser(dateTimeFormatter),
			LocalDateTime.class);

	addFormatterForFields(registry,
			new ReadableInstantPrinter(dateTimeFormatter),
			new DateTimeParser(dateTimeFormatter),
			ReadableInstant.class);

	// In order to retain backwards compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.formatters.containsKey(Type.DATE_TIME)) {
		addFormatterForFields(registry,
				new ReadableInstantPrinter(dateTimeFormatter),
				new DateTimeParser(dateTimeFormatter),
				Date.class, Calendar.class);
	}

	registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
	registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());

	registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
 
Example #20
Source File: MonthDayFormatter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
Example #21
Source File: MonthDayFormatter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
Example #22
Source File: JodaTimeFormattingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
Example #23
Source File: JodaTimeFormattingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public MonthDay getMonthDay() {
	return monthDay;
}
 
Example #24
Source File: JodaTimeFormatterRegistrar.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void registerFormatters(FormatterRegistry registry) {
	JodaTimeConverters.registerConverters(registry);

	DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
	DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
	DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateFormatter),
			new LocalDateParser(dateFormatter),
			LocalDate.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(timeFormatter),
			new LocalTimeParser(timeFormatter),
			LocalTime.class);

	addFormatterForFields(registry,
			new ReadablePartialPrinter(dateTimeFormatter),
			new LocalDateTimeParser(dateTimeFormatter),
			LocalDateTime.class);

	addFormatterForFields(registry,
			new ReadableInstantPrinter(dateTimeFormatter),
			new DateTimeParser(dateTimeFormatter),
			ReadableInstant.class);

	// In order to retain backwards compatibility we only register Date/Calendar
	// types when a user defined formatter is specified (see SPR-10105)
	if (this.formatters.containsKey(Type.DATE_TIME)) {
		addFormatterForFields(registry,
				new ReadableInstantPrinter(dateTimeFormatter),
				new DateTimeParser(dateTimeFormatter),
				Date.class, Calendar.class);
	}

	registry.addFormatterForFieldType(Period.class, new PeriodFormatter());
	registry.addFormatterForFieldType(Duration.class, new DurationFormatter());
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());

	registry.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
}
 
Example #25
Source File: MonthDayFormatter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}