本文整理匯總了Java中org.joda.time.MutableDateTime.toDateTime方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime.toDateTime方法的具體用法?Java MutableDateTime.toDateTime怎麽用?Java MutableDateTime.toDateTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.MutableDateTime
的用法示例。
在下文中一共展示了MutableDateTime.toDateTime方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIntervalStart
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
/**
* Given an array of strings (a row from a {@link java.sql.ResultSet}) and the
* {@link Granularity} used to make groupBy statements on time, it will parse out a {@link DateTime}
* for the row which represents the beginning of the interval it was grouped on.
*
* @param offset the last column before the date fields.
* @param recordValues The results returned by Sql needed to read the time columns.
* @param druidQuery The original druid query which was made using calling
* {@link #buildGroupBy(RelBuilder, Granularity, String)}.
*
* @return the datetime for the start of the interval.
*/
public DateTime getIntervalStart(int offset, String[] recordValues, DruidAggregationQuery<?> druidQuery) {
List<SqlDatePartFunction> times = timeGrainToDatePartFunctions(druidQuery.getGranularity());
DateTimeZone timeZone = getTimeZone(druidQuery);
if (times.isEmpty()) {
throw new UnsupportedOperationException("Can't parse dateTime for if no times were grouped on.");
}
MutableDateTime mutableDateTime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0, timeZone);
for (int i = 0; i < times.size(); i++) {
int value = Integer.parseInt(recordValues[offset + i]);
SqlDatePartFunction fn = times.get(i);
setDateTime(value, fn, mutableDateTime);
}
return mutableDateTime.toDateTime();
}
示例2: getLowerDateTimeBound
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException {
Range range = SearchExpressionUtils.parseRange(dateRange);
if (range == null) {
throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
}
if (range.getLowerBoundValue() != null) {
java.util.Date lowerRangeDate = null;
try{
lowerRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getLowerBoundValue());
}catch(ParseException pe){
GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
}
MutableDateTime dateTime = new MutableDateTime(lowerRangeDate);
dateTime.setMillisOfDay(0);
return dateTime.toDateTime();
}
return null;
}
示例3: getUpperDateTimeBound
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException {
Range range = SearchExpressionUtils.parseRange(dateRange);
if (range == null) {
throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
}
if (range.getUpperBoundValue() != null) {
java.util.Date upperRangeDate = null;
try{
upperRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getUpperBoundValue());
}catch(ParseException pe){
GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
}
MutableDateTime dateTime = new MutableDateTime(upperRangeDate);
// set it to the last millisecond of the day
dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1);
return dateTime.toDateTime();
}
return null;
}
示例4: getDateTimeBegin
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getDateTimeBegin() {
if (mDateTimeBegin == null) {
MutableDateTime begin = new MutableDateTime(getDate());
int hour = 0;
boolean excepted = true;
while (excepted) {
try {
begin.setHourOfDay(hour);
begin.setMinuteOfHour(0);
begin.setSecondOfMinute(0);
begin.setMillisOfSecond(0);
hour++;
excepted = false;
} catch (Exception e) {
}
}
mDateTimeBegin = begin.toDateTime();
}
return mDateTimeBegin;
}
示例5: getDateTimeEnd
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getDateTimeEnd() {
if (mDateTimeEnd == null) {
MutableDateTime end = new MutableDateTime(getDate());
int hour = 23;
boolean excepted = true;
while (excepted) {
try {
end.setHourOfDay(hour);
end.setMinuteOfHour(59);
end.setSecondOfMinute(59);
end.setMillisOfSecond(999);
hour--;
excepted = false;
} catch (Exception e) {
}
}
mDateTimeEnd = end.toDateTime();
}
return mDateTimeEnd;
}
示例6: nextTimeAfter
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
@CoverageIgnore
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
MutableDateTime nextTime = new MutableDateTime(afterTime);
nextTime.setMillisOfSecond(0);
nextTime.secondOfDay().add(1);
while (true) { // day of week
while (true) { // month
while (true) { // day of month
while (true) { // hour
while (true) { // minute
while (true) { // second
if (secondField.matches(nextTime.getSecondOfMinute())) {
break;
}
nextTime.secondOfDay().add(1);
}
if (minuteField.matches(nextTime.getMinuteOfHour())) {
break;
}
nextTime.minuteOfDay().add(1);
nextTime.secondOfMinute().set(0);
}
if (hourField.matches(nextTime.getHourOfDay())) {
break;
}
nextTime.hourOfDay().add(1);
nextTime.minuteOfHour().set(0);
nextTime.secondOfMinute().set(0);
}
if (dayOfMonthField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (monthField.matches(nextTime.getMonthOfYear())) {
break;
}
nextTime.addMonths(1);
nextTime.setDayOfMonth(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (dayOfWeekField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
return nextTime.toDateTime();
}
示例7: nextTimeAfter
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
MutableDateTime nextTime = new MutableDateTime(afterTime);
nextTime.setMillisOfSecond(0);
nextTime.secondOfDay().add(1);
while (true) { // day of week
while (true) { // month
while (true) { // day of month
while (true) { // hour
while (true) { // minute
while (true) { // second
if (secondField.matches(nextTime.getSecondOfMinute())) {
break;
}
nextTime.secondOfDay().add(1);
}
if (minuteField.matches(nextTime.getMinuteOfHour())) {
break;
}
nextTime.minuteOfDay().add(1);
nextTime.secondOfMinute().set(0);
}
if (hourField.matches(nextTime.getHourOfDay())) {
break;
}
nextTime.hourOfDay().add(1);
nextTime.minuteOfHour().set(0);
nextTime.secondOfMinute().set(0);
}
if (dayOfMonthField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (monthField.matches(nextTime.getMonthOfYear())) {
break;
}
nextTime.addMonths(1);
nextTime.setDayOfMonth(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
if (dayOfWeekField.matches(new LocalDate(nextTime))) {
break;
}
nextTime.addDays(1);
nextTime.setTime(0, 0, 0, 0);
checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
}
return nextTime.toDateTime();
}
示例8: getTimeAfter
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getTimeAfter(DateTime dateTime) {
try {
String[] fixedCronExp = appendYearField(expression.split("\\s+"));
validate(fixedCronExp);
MutableDateTime mdt = dateTime.toMutableDateTime();
mdt.setMillisOfSecond(0);
List<Integer> secondValues = parse(secondParsers, fixedCronExp[AbstractParser.DurationField.SECOND.getIndex()], dateTime, AbstractParser.DurationField.SECOND);
List<Integer> minuteValues = parse(minuteParsers, fixedCronExp[AbstractParser.DurationField.MINUTE.getIndex()], dateTime, AbstractParser.DurationField.MINUTE);
List<Integer> hourValues = parse(hourParsers, fixedCronExp[AbstractParser.DurationField.HOUR.getIndex()], dateTime, AbstractParser.DurationField.HOUR);
List<Integer> monthValues = parse(monthParsers, fixedCronExp[AbstractParser.DurationField.MONTH.getIndex()], dateTime, AbstractParser.DurationField.MONTH);
List<Integer> yearValues = parse(yearParsers, fixedCronExp[AbstractParser.DurationField.YEAR.getIndex()], dateTime, AbstractParser.DurationField.YEAR);
int yearStartIndex = searchNotLessThanIndex(yearValues, mdt.getYear());
for (int yearIndex = yearStartIndex, yearLen = yearValues.size(); yearIndex < yearLen; yearIndex++) {
int year = yearValues.get(yearIndex);
mdt.setYear(year);
int monthStartIndex = (year == dateTime.getYear()) ? searchNotLessThanIndex(monthValues, dateTime.getMonthOfYear()) : 0;
for (int monthIndex = monthStartIndex, monthLen = monthValues.size(); monthIndex < monthLen; monthIndex++) {
int month = monthValues.get(monthIndex);
mdt.setMonthOfYear(month);
List<Integer> dayValues = parseDayValueList(fixedCronExp, mdt.toDateTime());
int dayStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear())
? searchNotLessThanIndex(dayValues, dateTime.getDayOfMonth()) : 0;
int maxDayOfMonth = mdt.toDateTime().dayOfMonth().withMaximumValue().toLocalDate().getDayOfMonth();
for (int dayIndex = dayStartIndex, dayLen = dayValues.size(); dayIndex < dayLen; dayIndex++) {
int day = dayValues.get(dayIndex);
if (day > maxDayOfMonth) {
break;
}
mdt.setDayOfMonth(day);
int hourStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear() && day == dateTime.getDayOfMonth())
? searchNotLessThanIndex(hourValues, dateTime.getHourOfDay()) : 0;
for (int hourIndex = hourStartIndex, hourLen = hourValues.size(); hourIndex < hourLen; hourIndex++) {
int hour = hourValues.get(hourIndex);
mdt.setHourOfDay(hour);
int minuteStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay())
? searchNotLessThanIndex(minuteValues, dateTime.getMinuteOfHour()) : 0;
for (int minuteIndex = minuteStartIndex, minuteLen = minuteValues.size(); minuteIndex < minuteLen; minuteIndex++) {
int minute = minuteValues.get(minuteIndex);
int secondStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay() && minute == dateTime.getMinuteOfHour())
? searchNotLessThanIndex(secondValues, dateTime.getSecondOfMinute()) : 0;
mdt.setMinuteOfHour(minute);
for (int secondIndex = secondStartIndex, secondLen = secondValues.size(); secondIndex < secondLen; secondIndex++) {
int second = secondValues.get(secondIndex);
mdt.setSecondOfMinute(second);
if (mdt.isAfter(dateTime)) {
return mdt.toDateTime();
}
}
}
}
}
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return null;
}
示例9: getTimeBefore
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getTimeBefore(DateTime dateTime) {
try {
String[] fixedCronExp = appendYearField(expression.split("\\s+"));
validate(fixedCronExp);
MutableDateTime mdt = dateTime.toMutableDateTime();
mdt.setMillisOfSecond(0);
List<Integer> secondValues = parse(secondParsers, fixedCronExp[AbstractParser.DurationField.SECOND.getIndex()], dateTime, AbstractParser.DurationField.SECOND);
List<Integer> minuteValues = parse(minuteParsers, fixedCronExp[AbstractParser.DurationField.MINUTE.getIndex()], dateTime, AbstractParser.DurationField.MINUTE);
List<Integer> hourValues = parse(hourParsers, fixedCronExp[AbstractParser.DurationField.HOUR.getIndex()], dateTime, AbstractParser.DurationField.HOUR);
List<Integer> monthValues = parse(monthParsers, fixedCronExp[AbstractParser.DurationField.MONTH.getIndex()], dateTime, AbstractParser.DurationField.MONTH);
List<Integer> yearValues = parse(yearParsers, fixedCronExp[AbstractParser.DurationField.YEAR.getIndex()], dateTime, AbstractParser.DurationField.YEAR);
int yearStartIndex = searchNotGreaterThanIndex(yearValues, mdt.getYear());
for (int yearIndex = yearStartIndex; yearIndex >= 0; yearIndex--) {
int year = yearValues.get(yearIndex);
mdt.setYear(year);
int monthStartIndex = (year == dateTime.getYear()) ? searchNotGreaterThanIndex(monthValues, dateTime.getMonthOfYear())
: monthValues.size() - 1;
for (int monthIndex = monthStartIndex; monthIndex >= 0; monthIndex--) {
int month = monthValues.get(monthIndex);
mdt.setMonthOfYear(month);
List<Integer> dayValues = parseDayValueList(fixedCronExp, mdt.toDateTime());
int dayStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear())
? searchNotGreaterThanIndex(dayValues, dateTime.getDayOfMonth()) : dayValues.size() - 1;
int maxDayOfMonth = mdt.toDateTime().dayOfMonth().withMaximumValue().toLocalDate().getDayOfMonth();
for (int dayIndex = dayStartIndex; dayIndex >= 0; dayIndex--) {
int day = dayValues.get(dayIndex);
if (day > maxDayOfMonth) {
break;
}
mdt.setDayOfMonth(day);
int hourStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear() && day == dateTime.getDayOfMonth())
? searchNotGreaterThanIndex(hourValues, dateTime.getHourOfDay()) : hourValues.size() - 1;
for (int hourIndex = hourStartIndex; hourIndex >= 0; hourIndex--) {
int hour = hourValues.get(hourIndex);
mdt.setHourOfDay(hour);
int minuteStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay())
? searchNotGreaterThanIndex(minuteValues, dateTime.getMinuteOfHour()) : minuteValues.size() - 1;
for (int minuteIndex = minuteStartIndex; minuteIndex >= 0; minuteIndex--) {
int minute = minuteValues.get(minuteIndex);
mdt.setMinuteOfHour(minute);
int secondStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay() && minute == dateTime.getMinuteOfHour())
? searchNotGreaterThanIndex(secondValues, dateTime.getSecondOfMinute()) : secondValues.size() - 1;
for (int secondIndex = secondStartIndex; secondIndex >= 0; secondIndex--) {
int second = secondValues.get(secondIndex);
mdt.setSecondOfMinute(second);
if (mdt.isBefore(dateTime)) {
return mdt.toDateTime();
}
}
}
}
}
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return null;
}