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

项目: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();
    }
}
项目:message-gateway    文件:JsonParserHelper.java   
public MonthDay extractMonthDayNamed(final String parameterName, final JsonElement element) {

        MonthDay value = null;

        if (element.isJsonObject()) {
            final JsonObject object = element.getAsJsonObject();

            final String monthDayFormat = extractMonthDayFormatParameter(object);
            final Locale clientApplicationLocale = extractLocaleParameter(object);
            value = extractMonthDayNamed(parameterName, object, monthDayFormat, clientApplicationLocale);
        }
        return value;
    }
项目:message-gateway    文件:JsonParserHelper.java   
public MonthDay extractMonthDayNamed(final String parameterName, final JsonObject element, final String dateFormat,
        final Locale clientApplicationLocale) {
    MonthDay value = null;
    if (element.isJsonObject()) {
        final JsonObject object = element.getAsJsonObject();

        if (object.has(parameterName) && object.get(parameterName).isJsonPrimitive()) {

            final JsonPrimitive primitive = object.get(parameterName).getAsJsonPrimitive();
            final String valueAsString = primitive.getAsString();
            if (StringUtils.isNotBlank(valueAsString)) {
                try {
                    final DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat).withLocale(clientApplicationLocale);
                    value = MonthDay.parse(valueAsString.toLowerCase(clientApplicationLocale), formatter);
                } catch (final IllegalArgumentException e) {
                    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                    final ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.month.day",
                            "The parameter " + parameterName + " is invalid based on the monthDayFormat: '" + dateFormat
                                    + "' and locale: '" + clientApplicationLocale + "' provided:", parameterName, valueAsString,
                            dateFormat);
                    dataValidationErrors.add(error);

                    throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.",
                            dataValidationErrors);
                }
            }
        }

    }
    return value;
}
项目: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();
    }
}
项目:dashclock-birthday    文件:BirthdayRetriever.java   
private Birthday buildBirthday(ContentResolver contentResolver, Cursor c) {
    String birthDate = c.getString(1);
    if (birthDate == null) return null;

    // Analyze birthday string
    try {
        Matcher regexMatcher = regexDate.matcher(birthDate);

        if (regexMatcher.find()) {
            Birthday birthday = new Birthday(contentResolver, c.getLong(0));

            // Birthday *must* have a display name
            if (birthday.displayName == null) return null;

            birthday.birthdayDate = new MonthDay(
                    Integer.parseInt(regexMatcher.group(2)),
                    Integer.parseInt(regexMatcher.group(3))
            );

            if (!"-".equals(regexMatcher.group(1))) {
                birthday.year = Integer.parseInt(regexMatcher.group(1));
                birthday.unknownYear = false;
            }

            return birthday;
        }
    }
    catch (Exception e) {
        Log.e(TAG, "Error while analyzing birthday", e);
        return null;
    }

    return null;
}
项目:typeadapters    文件:MonthDayTypeAdapter.java   
@Override
public MonthDay read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  return MonthDay.parse(in.nextString());
}
项目:jfixture    文件:TestAllClassDataTypesAreSupported.java   
@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));
}
项目:ppinot    文件:MonthDayDeserializer.java   
@Override
public MonthDay deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException {

    String str = p.getText().trim();

    if (str.isEmpty()) {
        return null;
    }

    return MonthDay.parse(str, formatter);
}
项目:message-gateway    文件:FromJsonHelper.java   
public MonthDay extractMonthDayNamed(final String parameterName, final JsonElement element) {
    return this.helperDelegator.extractMonthDayNamed(parameterName, element);
}
项目:message-gateway    文件:FromJsonHelper.java   
public MonthDay extractMonthDayNamed(final String parameterName, final JsonObject object, final String dateFormat,
        final Locale clientApplicationLocale) {
    return this.helperDelegator.extractMonthDayNamed(parameterName, object, dateFormat, clientApplicationLocale);
}
项目:spring4-understanding    文件:MonthDayFormatter.java   
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
    return MonthDay.parse(text);
}
项目:spring4-understanding    文件:MonthDayFormatter.java   
@Override
public String print(MonthDay object, Locale locale) {
    return object.toString();
}
项目:spring4-understanding    文件:JodaTimeFormatterRegistrar.java   
public static void registerAdditionalFormatters(FormatterRegistry registry) {
    registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
    registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
项目:spring4-understanding    文件:JodaTimeFormattingTests.java   
public MonthDay getMonthDay() {
    return monthDay;
}
项目:spring4-understanding    文件:JodaTimeFormattingTests.java   
public void setMonthDay(MonthDay monthDay) {
    this.monthDay = monthDay;
}
项目:spring    文件:MonthDayFormatter.java   
@Override
public MonthDay parse(String text, Locale locale) throws ParseException {
    return MonthDay.parse(text);
}
项目:spring    文件:MonthDayFormatter.java   
@Override
public String print(MonthDay object, Locale locale) {
    return object.toString();
}
项目:spring    文件:JodaTimeFormatterRegistrar.java   
public static void registerAdditionalFormatters(FormatterRegistry registry) {
    registry.addFormatterForFieldType(YearMonth.class, new YearMonthFormatter());
    registry.addFormatterForFieldType(MonthDay.class, new MonthDayFormatter());
}
项目:typeadapters    文件:MonthDayTypeAdapterTest.java   
@Test
public void testSerialization() {
  MonthDay monthDay = new MonthDay(3,30);
  String json = gson.toJson(monthDay);
  assertEquals("\"--03-30\"", json);
}
项目:typeadapters    文件:MonthDayTypeAdapterTest.java   
@Test
public void testDeserialization() {
  MonthDay monthDay = gson.fromJson("\"--03-30\"", MonthDay.class);
  assertEquals(3, monthDay.getMonthOfYear());
  assertEquals(30, monthDay.getDayOfMonth());
}
项目:yourpisd    文件:DateHelper.java   
public static boolean isAprilFools() {
    MonthDay now = MonthDay.now();
    return (now.getDayOfMonth() == 1 || now.getDayOfMonth() == 2) && now.getMonthOfYear() == 4;
}
项目:jadira    文件:StringColumnMonthDayMapper.java   
@Override
public MonthDay fromNonNullValue(String s) {
    return MonthDay.parse(s);
}
项目:jadira    文件:StringColumnMonthDayMapper.java   
@Override
public String toNonNullValue(MonthDay value) {
    return value.toString();
}
项目:jadira    文件:MonthDayAsStringHolder.java   
public MonthDay getMonthDay() {
    return monthDay;
}
项目:jadira    文件:MonthDayAsStringHolder.java   
public void setMonthDay(MonthDay monthDay) {
    this.monthDay = monthDay;
}
项目:ppinot    文件:ScheduleItem.java   
public ScheduleItem(MonthDay from, MonthDay to, ScheduleBasic schedule) {
    this.from = from;
    this.to = to;
    this.schedule = schedule;
}
项目:ppinot    文件:ScheduleItem.java   
public MonthDay getFrom() {
    return from;
}
项目:ppinot    文件:ScheduleItem.java   
public MonthDay getTo() {
    return to;
}
项目:ppinot    文件:MonthDaySerializer.java   
@Override
public void serialize(MonthDay value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeString(formatter.print(value));
}