Example usage for org.joda.time LocalDate getMonthOfYear

List of usage examples for org.joda.time LocalDate getMonthOfYear

Introduction

In this page you can find the example usage for org.joda.time LocalDate getMonthOfYear.

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java

License:Apache License

public static LocalDate calculateLastBillingCycleDateBefore(final LocalDate date,
        final LocalDate previousBillCycleDate, final int billingCycleDay, final BillingPeriod billingPeriod) {
    LocalDate proposedDate = previousBillCycleDate;

    int numberOfPeriods = 0;
    while (!proposedDate.isAfter(date)) {
        proposedDate = previousBillCycleDate.plusMonths(numberOfPeriods * billingPeriod.getNumberOfMonths());
        numberOfPeriods += 1;/*from w  w  w  . ja  v  a2 s . c om*/
    }

    proposedDate = proposedDate.plusMonths(-billingPeriod.getNumberOfMonths());

    if (proposedDate.dayOfMonth().get() < billingCycleDay) {
        final int lastDayOfTheMonth = proposedDate.dayOfMonth().getMaximumValue();
        if (lastDayOfTheMonth < billingCycleDay) {
            proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(),
                    lastDayOfTheMonth);
        } else {
            proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(),
                    billingCycleDay);
        }
    }

    if (proposedDate.isBefore(previousBillCycleDate)) {
        // Make sure not to go too far in the past
        return previousBillCycleDate;
    } else {
        return proposedDate;
    }
}

From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java

License:Apache License

public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date,
        final int billingCycleDayLocal) {
    final int lastDayOfMonth = date.dayOfMonth().getMaximumValue();

    final LocalDate fixedDate;
    if (billingCycleDayLocal > lastDayOfMonth) {
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), lastDayOfMonth, date.getChronology());
    } else {/*  w w w  .  jav a  2 s  .c  o  m*/
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), billingCycleDayLocal,
                date.getChronology());
    }

    LocalDate proposedDate = fixedDate;
    while (proposedDate.isBefore(date)) {
        proposedDate = proposedDate.plusMonths(1);
    }
    return proposedDate;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isSameMonthAndDay(@Nonnull final LocalDate x, @Nonnull final LocalDate y) {
    return x.getMonthOfYear() == y.getMonthOfYear() && x.getDayOfMonth() == y.getDayOfMonth();
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

/**
 * Compare two dates by birthday. This means, the dates are only compared by
 * day and month, and <b>not</b> by year!
 *
 * @param aDate1//w w w.j ava  2 s.c  o  m
 *        First date. May be <code>null</code>.
 * @param aDate2
 *        Second date. May be <code>null</code>.
 * @return same as {@link Comparator#compare(Object, Object)}
 */
public static int birthdayCompare(@Nullable final LocalDate aDate1, @Nullable final LocalDate aDate2) {
    if (aDate1 == aDate2)
        return 0;
    if (aDate1 == null)
        return -1;
    if (aDate2 == null)
        return 1;

    // first compare month
    int ret = aDate1.getMonthOfYear() - aDate2.getMonthOfYear();
    if (ret == 0) {
        // on equal month, compare day of month
        ret = aDate1.getDayOfMonth() - aDate2.getDayOfMonth();
    }
    return ret;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isNewYearsEve(@Nonnull final LocalDate aDate) {
    if (aDate == null)
        throw new NullPointerException("date");
    return aDate.getMonthOfYear() == DateTimeConstants.DECEMBER && aDate.getDayOfMonth() == 31;
}

From source file:com.prayer.Utils.java

License:Apache License

public static String format(LocalDate date) {
        String format = getDateFormat(true);
        format = format.replace("DD", az(date.getDayOfMonth(), 2));

        try {/* w w w  .j  a v  a2s .co m*/
            format = format.replace("MMM", getGregMonth(date.getMonthOfYear() - 1));

        } catch (ArrayIndexOutOfBoundsException ex) {

            return "";
        }
        format = format.replace("MM", az(date.getMonthOfYear(), 2));
        format = format.replace("YYYY", az(date.getYear(), 4));
        format = format.replace("YY", az(date.getYear(), 2));
        return toArabicNrs(format);
    }

From source file:com.prayer.vakit.times.CalcTimes.java

License:Apache License

@Override
    public String _getTime(LocalDate date, int time) {
        List<String> times = getPrayTime().getDatePrayerTimes(date.getYear(), date.getMonthOfYear(),
                date.getDayOfMonth(), getLat(), getLng());
        times.remove(4);/* w w w  .  java  2 s.  c om*/
        return times.get(time);
    }

From source file:com.qubit.solution.fenixedu.integration.ldap.service.LdapIntegration.java

License:Open Source License

@Atomic
private static void updatePerson(final Person person, final String instituionalEmail,
        final String personalEmail, final String birthDate, final String documentID, final String sex,
        final String givenNames, final String surnames) {

    // if (person.getDocumentIdNumber() != null &&
    // !person.getDocumentIdNumber().equals(documentID)) {
    // throw new IllegalStateException(
    // "Seems we are trying to update a person that does not match the ID.
    // This should not happen!");
    // }//  w  w w  .  j  a v  a 2s  .c om

    String institutionalEmailAddressValue = person.getInstitutionalEmailAddressValue();
    if (!StringUtils.isEmpty(instituionalEmail) && (institutionalEmailAddressValue == null
            || !institutionalEmailAddressValue.equals(instituionalEmail))) {
        person.setInstitutionalEmailAddressValue(instituionalEmail);
    }

    List<? extends PartyContact> personalEmails = person.getPartyContacts(EmailAddress.class,
            PartyContactType.PERSONAL);
    if (!StringUtils.isEmpty(personalEmail) && personalEmails.stream()
            .filter(email -> email.getPresentationValue().equals(personalEmail)).count() == 0) {
        EmailAddress.createEmailAddress(person, personalEmail, PartyContactType.PERSONAL, false);
    }

    if (!StringUtils.isEmpty(birthDate)) {
        String format = "yyyyMMddHHmmss'Z'";
        if (birthDate.contains(".")) {
            format = "yyyyMMddHHmmss.SSS'Z'";
        }
        LocalDate parseLocalDate = new DateTimeFormatterFactory(format).createDateTimeFormatter()
                .parseLocalDate(birthDate);
        YearMonthDay dateOfBirthYearMonthDay = person.getDateOfBirthYearMonthDay();
        if (dateOfBirthYearMonthDay == null || !parseLocalDate.isEqual(dateOfBirthYearMonthDay)) {
            YearMonthDay yearMonthDay = new YearMonthDay(parseLocalDate.getYear(),
                    parseLocalDate.getMonthOfYear(), parseLocalDate.getDayOfMonth());
            person.setDateOfBirthYearMonthDay(yearMonthDay);
        }
    }

    if (!StringUtils.isEmpty(documentID) && !person.getDocumentIdNumber().equals(documentID)) {
        person.setDocumentIdNumber(documentID);
    }

    if (!StringUtils.isEmpty(sex)) {
        Gender genderInLdap = "M".equals(sex) ? Gender.MALE : "F".equals(sex) ? Gender.FEMALE : null;
        if (genderInLdap != null && person.getGender() != genderInLdap) {
            person.setGender(genderInLdap);
        }
    }

    if (!StringUtils.isEmpty(givenNames) && !StringUtils.isEmpty(surnames)
            && !equalInAnyLanguage(person.getPartyName(), givenNames + " " + surnames)) {
        String displayName = givenNames.split(" ")[0] + " " + surnames.split(" ")[0];
        person.getProfile().changeName(givenNames, surnames, displayName);
    }

}

From source file:com.rappsantiago.weighttracker.dialog.DatePickerDialogFragment.java

License:Apache License

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LocalDate now = new LocalDate();

    int year = now.getYear();
    int monthOfYear = now.getMonthOfYear();
    int dayOfMonth = now.getDayOfMonth();

    Dialog datePickerDialog = new DatePickerDialog(getActivity(), mOnDateSetListener, year, monthOfYear - 1,
            dayOfMonth);/*from   ww  w . j a v  a 2 s  .com*/
    Util.hideSoftKeyboard(getContext(), getActivity().getCurrentFocus());

    return datePickerDialog;
}

From source file:com.sonicle.webtop.mail.FolderCache.java

License:Open Source License

public void archiveMessages(long uids[], String folderarchive, boolean fullthreads) throws MessagingException {
    if (canDelete()) {
        Message mmsgs[] = getMessages(uids, fullthreads);
        MailUserSettings mus = ms.getMailUserSettings();
        String sep = "" + account.getFolderSeparator();
        String xfolderarchive = folderarchive;
        Message xmmsg[] = new Message[1];
        for (Message mmsg : mmsgs) {
            folderarchive = xfolderarchive;
            LocalDate ld = getArchivingReferenceDate(mmsg);
            FolderCache fcto = account.checkCreateAndCacheFolder(folderarchive);
            if (mus.getArchiveMode().equals(MailSettings.ARCHIVING_MODE_YEAR)) {
                folderarchive += sep + ld.getYear();
                fcto = account.checkCreateAndCacheFolder(folderarchive);
            } else if (mus.getArchiveMode().equals(MailSettings.ARCHIVING_MODE_MONTH)) {
                folderarchive += sep + ld.getYear();
                fcto = account.checkCreateAndCacheFolder(folderarchive);
                folderarchive += sep + ld.getYear() + "-"
                        + StringUtils.leftPad(ld.getMonthOfYear() + "", 2, '0');
                fcto = account.checkCreateAndCacheFolder(folderarchive);
            }//from  w w w.  j  a va2 s. c  o m
            if (mus.isArchiveKeepFoldersStructure()) {
                String fname = foldername;
                //strip prefix is present
                String prefix = account.getFolderPrefix();
                if (prefix != null && fname.startsWith(prefix)) {
                    fname = fname.substring(prefix.length());
                }
                if (account.isUnderSharedFolder(foldername)) {
                    String mainfolder = account.getMainSharedFolder(foldername);
                    if (fname.equals(mainfolder))
                        fname = "INBOX";
                    else
                        fname = fname.substring(mainfolder.length() + 1);
                }
                folderarchive += sep + fname;
                fcto = account.checkCreateAndCacheFolders(folderarchive);
            }
            xmmsg[0] = mmsg;
            folder.copyMessages(xmmsg, fcto.folder);
            fcto.setForceRefresh();
            fcto.modified = true;
        }
        folder.setFlags(mmsgs, new Flags(Flags.Flag.DELETED), true);
        removeDHash(uids);
        folder.expunge();
        setForceRefresh();
        modified = true;
    } else
        throw new MessagingException(ms.lookupResource(MailLocaleKey.PERMISSION_DENIED));
}