org.joda.time.LocalDate#toString ( )源码实例Demo

下面列出了org.joda.time.LocalDate#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hive-third-functions   文件: UDFTypeOfDay.java
public IntWritable evaluate(TimestampWritable t) {
    if (t == null) {
        return null;
    }

    try {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(t.getTimestamp());
        LocalDate date = LocalDate.fromCalendarFields(calendar);
        String dateString = date.toString(DEFAULT_DATE_FORMATTER);

        return evaluate(new Text(dateString));
    } catch (Exception e) {
        return null;
    }
}
 
源代码2 项目: prayer-times-android   文件: WebTimes.java
private int getSyncedDays() {
    LocalDate date = LocalDate.now().plusDays(1);
    int i = 0;
    while (i < 45) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00"))
                return i;
        }
        i++;
        date = date.plusDays(1);
    }
    return i;

}
 
源代码3 项目: prayer-times-android   文件: WebTimes.java
@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}
 
private static String prepareContent(DatasetInfoHolder info, ArrayList<Group> groups) {
    JsonObject content = new JsonObject();
    JsonArray values = putFieldValuesInJson(groups);

    // Retrieve current date
    LocalDate currentDate = new LocalDate();
    String completeDate = currentDate.toString(Constants.DATE_FORMAT);

    content.addProperty(Constants.ORG_UNIT_ID, info.getOrgUnitId());
    content.addProperty(Constants.DATA_SET_ID, info.getFormId());
    content.addProperty(Constants.PERIOD, info.getPeriod());
    content.addProperty(Constants.COMPLETE_DATE, completeDate);
    content.add(Constants.DATA_VALUES, values);

    JsonArray categoryOptions = putCategoryOptionsInJson(info.getCategoryOptions());
    if (categoryOptions != null) {
        content.add(Constants.ATTRIBUTE_CATEGORY_OPTIONS, categoryOptions);
    }

    return content.toString();
}
 
源代码5 项目: dhis2-android-datacapture   文件: MonthIterator.java
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(1)))  && counter < 12) {
        String month = checkDate.monthOfYear().getAsShortText();
        String year = checkDate.year().getAsString();

        String date = checkDate.toString(DATE_FORMAT);
        String label = String.format(DATE_LABEL_FORMAT, month, year);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusMonths(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
protected String getFormattedDate(LocalDate date) {
    final int dayOfMonth = date.getDayOfMonth();
    final String month = date.toString("MMMM", getLocale());
    final int year = date.getYear();

    return new StringBuilder()
            .append(dayOfMonth)
            .append( (getLocale().equals(LocaleUtils.PT) ? EMPTY_STR : getDayOfMonthSuffixOfDate(dayOfMonth)) )
            .append(SINGLE_SPACE)
            .append(BundleUtil.getString(Bundle.APPLICATION, getLocale(), "label.of"))
            .append(SINGLE_SPACE)
            .append( (getLocale().equals(LocaleUtils.PT)) ? month.toLowerCase() : month )
            .append(SINGLE_SPACE)
            .append(BundleUtil.getString(Bundle.APPLICATION, getLocale(), "label.of"))
            .append(SINGLE_SPACE)
            .append(year)
            .toString();
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays() - 1;
    WeeklySundayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklySundayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;
    int quantity = checkDate.weekOfWeekyear().getMaximumValue();
    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusWeeks(1).minusDays(1))) && counter < quantity) {
        String year = checkDate.year().getAsString();
        String cWeekNumber = "" + (Integer.parseInt(checkDate.weekOfWeekyear().getAsString())+ 1 );
        String cDate = checkDate.toString();
        String nDate = checkDate.plusWeeks(1).minusDays(1).toString();

        String date = String.format(DATE_FORMAT, year, W, cWeekNumber);
        String label = String.format(DATE_LABEL_FORMAT, W, cWeekNumber, cDate, nDate);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusWeeks(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusMonths(1).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(1), new LocalDate()).getDays();
    MonthlyExpiryDayValidator monthlyExpiryDayValidator = new MonthlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN));
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_APRIL ? DateTimeConstants.APRIL
                    : DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays();
    SixMonthlyAprilExpiryDayValidator monthlyExpiryDayValidator =
            new SixMonthlyAprilExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN) + previousPeriodStart);
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
@Test
public void testCanEditPreviousPeriodEndsSameTodayMinusDifferencePlusTwoExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusMonths(1).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(1), new LocalDate()).getDays() + 2;
    MonthlyExpiryDayValidator monthlyExpiryDayValidator = new MonthlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN));
    assertTrue(monthlyExpiryDayValidator.canEdit());
}
 
@Test
public void testCanEditPreviousPeriodEndsSameTodayMinusExpiryDaysPlusOne() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.WEDNESDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays() + 1;
    WeeklyWednesdayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklyWednesdayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertTrue(weeklyExpiryDayValidator.canEdit());
}
 
源代码13 项目: Simple-Dilbert   文件: DilbertPreferences.java
/**
 * Removes cached URL for provided date
 *
 * @param currentDate date for which the cache should be deleted
 * @return if the removal was successfull
 */
public boolean removeCache(LocalDate currentDate) {
    String dateString = currentDate.toString(DilbertPreferences.DATE_FORMATTER);
    return editor
            .remove(dateString + "_title") // cached title
            .remove(dateString) // cached url
            .commit();
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_APRIL ? DateTimeConstants.APRIL
                    : DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays() - 1;
    SixMonthlyAprilExpiryDayValidator monthlyExpiryDayValidator =
            new SixMonthlyAprilExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN) + previousPeriodStart);
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays();
    WeeklyExpiryDayValidator weeklyExpiryDayValidator = new WeeklyExpiryDayValidator(expiryDays,
            periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;


    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(6))) && counter < 2) {
        String year = checkDate.year().getAsString();
        String yearLastPeriod = Integer.parseInt(year)+1+"";
        String label;
        String date;

        if (checkDate.getMonthOfYear() >= APR && checkDate.getMonthOfYear() <= SEP) {
            label = String.format(DATE_LABEL_FORMAT, APR_STR_LONG, SEP_STR_LONG, year);
            date = year + S1;
        } else {
            label = String.format(DATE_LABEL_FORMAT, OCT_STR_LONG +" "+ year, MAR_STR_LONG, yearLastPeriod);
            date = year + S2;
        }


        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }
        checkDate = checkDate.plusMonths(6);
        counter++;
    }

    Collections.reverse(dates);
    return dates;
}
 
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferencePlusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays() + 1;
    FinancialYearOctExpiryDayValidator yearlyExpiryDayValidator =
            new FinancialYearOctExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
源代码18 项目: prayer-times-android   文件: ImsakiyeFragment.java
@Nullable
@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.vakit_imsakiye, parent, false);
    }
    ViewGroup v = (ViewGroup) convertView;
    CharSequence[] a;
    if (position == 0) {
        a = new String[]{getString(R.string.date), getString(R.string.fajr), getString(R.string.sun), getString(R.string.zuhr), getString(R.string.asr), getString(R.string.maghrib), getString(R.string.ishaa)};
    } else if (times == null) {
        a = new String[]{"00:00", "00:00", "00:00", "00:00", "00:00", "00:00", "00:00"};
    } else {
        LocalDate cal = (LocalDate) getItem(position - 1);

        LocalDateTime[] daytimes = {
                times.getTime(cal, Vakit.FAJR.ordinal()),
                times.getTime(cal, Vakit.SUN.ordinal()),
                times.getTime(cal, Vakit.DHUHR.ordinal()),
                times.getTime(cal, Vakit.ASR.ordinal()),
                times.getTime(cal, Vakit.MAGHRIB.ordinal()),
                times.getTime(cal, Vakit.ISHAA.ordinal())};

        a = new CharSequence[]{cal.toString("dd.MM"),
                LocaleUtils.formatTimeForHTML(daytimes[0].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[1].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[2].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[3].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[4].toLocalTime()),
                LocaleUtils.formatTimeForHTML(daytimes[5].toLocalTime())};
    }

    for (int i = 0; i < 7; i++) {
        TextView tv = (TextView) v.getChildAt(i);
        tv.setText(a[i]);
    }
    if (position == today) {
        v.setBackgroundResource(R.color.colorPrimary);
    } else if (position == 0) {
        v.setBackgroundResource(R.color.accent);
    } else if ((position % 2) == 0) {
        v.setBackgroundResource(R.color.colorPrimaryLight);
    } else {
        v.setBackgroundResource(R.color.background);
    }

    return v;
}
 
源代码19 项目: jadira   文件: DateColumnLocalDateMapper.java
@Override
public String toNonNullString(LocalDate value) {
    return value.toString();
}
 
源代码20 项目: super-csv   文件: FmtLocalDate.java
/**
 * {@inheritDoc}
 */
@Override
protected String format(final LocalDate jodaType) {
	return jodaType.toString();
}