Java implements an example of calculating periodic reminders

  • 2020-04-01 03:15:05
  • OfStack

Holidays such as father's day and mother's day can be calculated or defined as the best Friday of the month to facilitate the scheduling of meetings.



public static String nextTime(String strdate, int cyclePriod,
String loopPriod, Boolean isLunar) {
String returnValue = "";
int[] dates = DateUtils.genDate(strdate);
ChineseCalendar cCalendar = new ChineseCalendar();
cCalendar.setGregorianYear(dates[0]);
cCalendar.setGregorianMonth(dates[1]);
cCalendar.setGregorianDate(dates[2]);
if ("m".equalsIgnoreCase(loopPriod)) //Processing on
{
if (isLunar) {
for (int i = 0; i < cyclePriod; i++) {
cCalendar.nextChineseMonth();
}
returnValue = DateUtils.genDate(cCalendar.getGregorianYear(),
cCalendar.getGregorianMonth(),
cCalendar.getGregorianDate());
} else {
returnValue = DateUtils.calDate(strdate, cyclePriod, 2);
}
} else if ("d".equalsIgnoreCase(loopPriod)) //To deal with,
{
returnValue = DateUtils.calDate(strdate, cyclePriod, 5);
} else if ("y".equalsIgnoreCase(loopPriod)) //In dealing with
{
if (isLunar) {
cCalendar.addChineseYear(cyclePriod);
returnValue = DateUtils.genDate(cCalendar.getGregorianYear(),
cCalendar.getGregorianMonth(),
cCalendar.getGregorianDate());
} else {
returnValue = DateUtils.calDate(strdate, cyclePriod, 1);
}
} else if ("w".equalsIgnoreCase(loopPriod)) //Week of treatment
{
returnValue = DateUtils.calDate(strdate, cyclePriod, 3);
} else if ("h".equalsIgnoreCase(loopPriod)) //Processing hours
{
returnValue = TimeUtils.addTime(strdate, 0, cyclePriod);
} else if ("f".equalsIgnoreCase(loopPriod)) //Deal with minute
{
returnValue = TimeUtils.addTime(strdate, 1, cyclePriod);
} else if ("s".equalsIgnoreCase(loopPriod)) //Processing seconds
{
returnValue = TimeUtils.addTime(strdate, 2, cyclePriod);
} else //Processing unconventional cycle
{
if ("m".equalsIgnoreCase(StringUtils.left(loopPriod, 1))) {
String mnb = loopPriod.substring(1, 2);
String wnb = "";
int mnbValue = 0;
int wnbValue = 0;
if (loopPriod.indexOf("w") > 1) {
wnb = loopPriod.substring(loopPriod.indexOf("w") + 1,
loopPriod.indexOf("w") + 2);
mnbValue = Integer.parseInt(loopPriod.substring(2,
loopPriod.indexOf("w")));
wnbValue = Integer.parseInt(loopPriod.substring(
loopPriod.indexOf("w") + 1, loopPriod.length()));
if ("n".equalsIgnoreCase(mnb)) {
returnValue = getBeforeWeekDay(strdate, mnbValue,
wnbValue);
} else if ("b".equalsIgnoreCase(mnb)) {
returnValue = getBackWeekDay(strdate, mnbValue,
wnbValue);
}
} else {
mnbValue = Integer.parseInt(loopPriod.substring(2,
loopPriod.length())) - 1;
if ("n".equalsIgnoreCase(mnb)) {
returnValue = calDate(giveMonthFirst(strdate),
mnbValue, 5);
} else if ("b".equalsIgnoreCase(mnb)) {
returnValue = calDate(giveMonthLast(strdate),
-mnbValue, 5);

}
}
} else if ("w".equalsIgnoreCase(StringUtils.left(loopPriod, 1))) {
String week = StringUtils.right(loopPriod,
loopPriod.length() - 1);
strdate = calDate(strdate, cyclePriod - 1, 3);
while (true) {
strdate = calDate(strdate, 1, 5);
if (week.indexOf(String.valueOf(getWeekDay(strdate))) >= 0) {
returnValue = strdate;
break;
}
}
}
}
return returnValue;
}


Related articles: