com.crosstreelabs.phpfunctions.dateformat.OrdinalDayOfWeekSuffixPrinter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phpfunctions Show documentation
Show all versions of phpfunctions Show documentation
Provides a selection of PHP's functionality in Java, including date/time formatting.
The newest version!
package com.crosstreelabs.phpfunctions.dateformat;
import java.util.Locale;
import org.joda.time.ReadablePartial;
public class OrdinalDayOfWeekSuffixPrinter extends AbstractPrinterParser {
@Override
public String fromPartial(ReadablePartial partial, Locale locale) {
// Surely there's a better way to do this?
int n = Integer.valueOf(partial.getChronology().dayOfMonth().getAsText(partial, locale));
if (n >= 11 && n <= 13) {
return "th";
}
switch (n % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
@Override
public int estimatePrintedLength() {
return 2;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy