Java Code Examples for org.joda.time.LocalDate#toString()

The following examples show how to use org.joda.time.LocalDate#toString() . 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: UDFTypeOfDay.java    From hive-third-functions with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: AdministrativeOfficeDocument.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: MonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
}
 
Example 4
Source File: ReportUploadProcessor.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();
}
 
Example 5
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
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;

}
 
Example 7
Source File: FinancialYearOctExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 8
Source File: WeeklySundayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 9
Source File: SixMonthAprilIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 10
Source File: WeeklyExpiryDateValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 11
Source File: SixMonthlyAprilExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 12
Source File: DilbertPreferences.java    From Simple-Dilbert with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 13
Source File: WeeklyWednesdayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 14
Source File: MonthlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 15
Source File: SixMonthlyAprilExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 16
Source File: MonthlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
}
 
Example 17
Source File: WeekSundayIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 18
Source File: DateColumnLocalDateMapper.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public String toNonNullString(LocalDate value) {
    return value.toString();
}
 
Example 19
Source File: ImsakiyeFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 20
Source File: FmtLocalDate.java    From super-csv with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected String format(final LocalDate jodaType) {
	return jodaType.toString();
}