类org.joda.time.MonthDay源码实例Demo

下面列出了怎么用org.joda.time.MonthDay的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: RememBirthday   文件: DateUnknownYear.java
/**
 * 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();
    }
}
 
源代码2 项目: RememBirthday   文件: DateUnknownYear.java
/**
 * 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();
    }
}
 
@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));
}
 
源代码4 项目: spring-analysis-note   文件: MonthDayFormatter.java
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
源代码5 项目: spring-analysis-note   文件: MonthDayFormatter.java
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
@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());
}
 
public MonthDay getMonthDay() {
	return monthDay;
}
 
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
源代码9 项目: java-technology-stack   文件: MonthDayFormatter.java
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
源代码10 项目: java-technology-stack   文件: MonthDayFormatter.java
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
@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());
}
 
public MonthDay getMonthDay() {
	return monthDay;
}
 
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
源代码14 项目: lams   文件: MonthDayFormatter.java
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
源代码15 项目: lams   文件: MonthDayFormatter.java
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
源代码16 项目: lams   文件: JodaTimeFormatterRegistrar.java
public static void registerAdditionalFormatters(FormatterRegistry registry) {
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
 
源代码17 项目: spring4-understanding   文件: MonthDayFormatter.java
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
	return MonthDay.parse(text);
}
 
源代码18 项目: spring4-understanding   文件: MonthDayFormatter.java
@Override
public String print(MonthDay object, Locale locale) {
	return object.toString();
}
 
public static void registerAdditionalFormatters(FormatterRegistry registry) {
	registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
	registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
 
public MonthDay getMonthDay() {
	return monthDay;
}
 
public void setMonthDay(MonthDay monthDay) {
	this.monthDay = monthDay;
}
 
源代码22 项目: jadira   文件: StringColumnMonthDayMapper.java
@Override
public MonthDay fromNonNullValue(String s) {
    return MonthDay.parse(s);
}
 
源代码23 项目: jadira   文件: StringColumnMonthDayMapper.java
@Override
public String toNonNullValue(MonthDay value) {
    return value.toString();
}
 
源代码24 项目: jadira   文件: MonthDayAsStringHolder.java
public MonthDay getMonthDay() {
    return monthDay;
}
 
源代码25 项目: jadira   文件: MonthDayAsStringHolder.java
public void setMonthDay(MonthDay monthDay) {
    this.monthDay = monthDay;
}
 
 类所在包
 同包方法