下面列出了org.joda.time.MutableDateTime#setYear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
cal.setYear(yr);
cal.setMonthOfYear(1);
cal.setDayOfMonth(1);
int firstD = 1;
while (cal.getDayOfWeek() != firstDay)
cal.setDayOfMonth(++firstD);
cal.setYear(yr);
cal.setMonthOfYear(mo);
cal.setDayOfMonth(da);
int dayOfYear = cal.getDayOfYear();
if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
cal.setYear(yr);
cal.setMonthOfYear(1);
cal.setDayOfMonth(1);
int firstD = 1;
while (cal.getDayOfWeek() != firstDay)
cal.setDayOfMonth(++firstD);
cal.setYear(yr);
cal.setMonthOfYear(mo);
cal.setDayOfMonth(da);
int dayOfYear = cal.getDayOfYear();
if (dayOfYear < firstD) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
else return (dayOfYear - firstD) / 7 +1;
}
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
if (xts == null) {
return null;
}
MutableDateTime dateTime = new MutableDateTime();
try {
dateTime.setYear(xts.getYear());
dateTime.setMonthOfYear(xts.getMonth());
dateTime.setDayOfMonth(xts.getDay());
dateTime.setHourOfDay(xts.getHour());
dateTime.setMinuteOfHour(xts.getMinute());
dateTime.setSecondOfMinute(xts.getSecond());
dateTime.setMillisOfSecond(xts.getMillisecond());
DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
if (tz != null) {
dateTime.setZoneRetainFields(tz);
}
return Long.valueOf(dateTime.getMillis());
} catch (IllegalArgumentException e) {
throw new ComponentException(e);
}
}
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
cal.setYear(yr);
cal.setMonthOfYear(1);
cal.setDayOfMonth(1);
int firstD = 1;
while (cal.getDayOfWeek() != firstDay)
cal.setDayOfMonth(++firstD);
cal.setYear(yr);
cal.setMonthOfYear(mo);
cal.setDayOfMonth(da);
int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
if (firstD < 4)
{
if (week < 0) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
else return yr * 100 + week / 7 + 1;
}
else
{
if (week < 0) return yr * 100 + 1;
else return yr * 100 + week / 7 + 2;
}
}
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
cal.setYear(yr);
cal.setMonthOfYear(1);
cal.setDayOfMonth(1);
int firstD = 1;
while (cal.getDayOfWeek() != firstDay)
cal.setDayOfMonth(++firstD);
cal.setYear(yr);
cal.setMonthOfYear(mo);
cal.setDayOfMonth(da);
int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
if (firstD < 4)
{
if (week < 0) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
else return week / 7 + 1;
}
else
{
if (week < 0) return 1;
else return week / 7 + 2;
}
}
private void checkJodaSetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
for (int i = 0; i < AVERAGE; i++) {
start("Joda", "setYear");
for (int j = 0; j < COUNT; j++) {
dt.setYear(1972);
if (dt == null) {System.out.println("Anti optimise");}
}
end(COUNT);
}
}
private void checkJISOSetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime();
for (int i = 0; i < AVERAGE; i++) {
start("JISO", "setYear");
for (int j = 0; j < COUNT; j++) {
dt.setYear(1972);
if (dt == null) {System.out.println("Anti optimise");}
}
end(COUNT);
}
}
private void checkJodaSetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
for (int i = 0; i < AVERAGE; i++) {
start("Joda", "setYear");
for (int j = 0; j < COUNT; j++) {
dt.setYear(1972);
if (dt == null) {System.out.println("Anti optimise");}
}
end(COUNT);
}
}
private void checkJISOSetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime();
for (int i = 0; i < AVERAGE; i++) {
start("JISO", "setYear");
for (int j = 0; j < COUNT; j++) {
dt.setYear(1972);
if (dt == null) {System.out.println("Anti optimise");}
}
end(COUNT);
}
}