Java Code Examples for java.util.Calendar.DAY_OF_MONTH

The following are Jave code examples for showing how to use DAY_OF_MONTH of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-data-model   File: SearchDateConversion.java   View Source Code Vote up 8 votes
/**
 * @param dateAndResolution
 * @return String date
 */
public static String getDateEnd(Pair<Date, Integer> dateAndResolution)
{
    Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
    cal.setTime(dateAndResolution.getFirst());
    switch (dateAndResolution.getSecond())
    {
        case Calendar.YEAR:
            cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH));
        case Calendar.MONTH:
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        case Calendar.DAY_OF_MONTH:
            cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
        case Calendar.HOUR_OF_DAY:
            cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
        case Calendar.MINUTE:
            cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
        case Calendar.SECOND:
            cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
        case Calendar.MILLISECOND:
        default:
    }
    SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
    formatter.setTimeZone(UTC_TIMEZONE);
    return formatter.format(cal.getTime());
}
 
Example 2
Project: alfresco-data-model   File: SearchDateConversion.java   View Source Code Vote up 8 votes
/**
 * @param dateAndResolution
 * @return String date
 */
public static String getDateStart(Pair<Date, Integer> dateAndResolution)
{
    Calendar cal = Calendar.getInstance(I18NUtil.getLocale());
    cal.setTime(dateAndResolution.getFirst());
    switch (dateAndResolution.getSecond())
    {
        case Calendar.YEAR:
            cal.set(Calendar.MONTH, cal.getActualMinimum(Calendar.MONTH));
        case Calendar.MONTH:
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        case Calendar.DAY_OF_MONTH:
            cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
        case Calendar.HOUR_OF_DAY:
            cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
        case Calendar.MINUTE:
            cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
        case Calendar.SECOND:
            cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
        case Calendar.MILLISECOND:
        default:
    }
    SimpleDateFormat formatter = CachingDateFormat.getSolrDatetimeFormat();
    formatter.setTimeZone(UTC_TIMEZONE);
    return formatter.format(cal.getTime());
}
 
Example 3
Project: oscm   File: TimeSlice.java   View Source Code Vote up 7 votes
/**
 * Operation is based on java util calendar in order to support daylight
 * saving times.
 */
public TimeSlice previous() {
    long newStart = start;
    long newEnd = end;
    Calendar temp = Calendar.getInstance();
    temp.setTimeInMillis(start);
    int field = 0;
    switch (period) {
    case HOUR:
        field = Calendar.HOUR_OF_DAY;
        break;
    case DAY:
        field = Calendar.DAY_OF_MONTH;
        break;
    case WEEK:
        field = Calendar.WEEK_OF_YEAR;
        break;
    case MONTH:
        field = Calendar.MONTH;
        break;
    default:
        break;
    }
    temp.add(field, -1);
    newStart = temp.getTimeInMillis();
    temp.setTimeInMillis(end);
    temp.add(field, -1);
    newEnd = temp.getTimeInMillis();
    return new TimeSlice(newStart, newEnd, period);
}
 
Example 4
Project: elasticsearch_my   File: DateField.java   View Source Code Vote up 6 votes
static ValueSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {
    switch (method) {
        case GETVALUE_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.MIN);
        case ISEMPTY_METHOD:
            return new EmptyMemberValueSource(fieldData);
        case SIZE_METHOD:
            return new CountMethodValueSource(fieldData);
        case MINIMUM_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.MIN);
        case MAXIMUM_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.MAX);
        case AVERAGE_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.AVG);
        case MEDIAN_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.MEDIAN);
        case SUM_METHOD:
            return new FieldDataValueSource(fieldData, MultiValueMode.SUM);
        case COUNT_METHOD:
            return new CountMethodValueSource(fieldData);
        case GET_YEAR_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.YEAR);
        case GET_MONTH_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MONTH);
        case GET_DAY_OF_MONTH_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.DAY_OF_MONTH);
        case GET_HOUR_OF_DAY_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.HOUR_OF_DAY);
        case GET_MINUTES_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MINUTE);
        case GET_SECONDS_METHOD:
            return new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.SECOND);
        default:
            throw new IllegalArgumentException("Member method [" + method + "] does not exist for date field [" + fieldName + "].");
    }
}
 
Example 5
Project: CosmoCalendar   File: CalendarUtils.java   View Source Code Vote up 6 votes
public static boolean isDayDisabledByCriteria(Day day, DisabledDaysCriteria criteria) {
    int field = -1;
    switch (criteria.getCriteriaType()){
        case DAYS_OF_MONTH:
            field = Calendar.DAY_OF_MONTH;
            break;

        case DAYS_OF_WEEK:
            field = Calendar.DAY_OF_WEEK;
            break;
    }

    for(int dayInt : criteria.getDays()){
        if(dayInt == day.getCalendar().get(field)){
            return true;
        }
    }
    return false;
}
 
Example 6
Project: Remindy   File: TaskUtil.java   View Source Code Vote up 6 votes
private static int getDateFieldFromRepeatType(ReminderRepeatType repeatType) {

        switch (repeatType) {
            case DAILY: return Calendar.DAY_OF_MONTH;
            case WEEKLY: return Calendar.WEEK_OF_YEAR;
            case MONTHLY: return Calendar.MONTH;
            case YEARLY: return Calendar.YEAR;
            default: throw new InvalidParameterException("Invalid RepeatType parameter in TaskUtil.getRepeatingReminderEndCalendar()");
        }
    }
 
Example 7
Project: NeverLag   File: DateUtils.java   View Source Code Vote up 6 votes
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
	boolean future = false;
	if (toDate.equals(fromDate)) {
		return I18N.tr("now");
	}
	if (toDate.after(fromDate)) {
		future = true;
	}
	StringBuilder sb = new StringBuilder();
	int[] types = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
	String[] names = {
		I18N.tr("year"), I18N.tr("years"),
		I18N.tr("month"), I18N.tr("months"),
		I18N.tr("day"), I18N.tr("days"),
		I18N.tr("hour"), I18N.tr("hours"),
		I18N.tr("minute"), I18N.tr("minutes"),
		I18N.tr("second"), I18N.tr("seconds")
	};
	int accuracy = 0;
	for (int i = 0; i < types.length; i++) {
		if (accuracy > 2) {
			break;
		}
		int diff = dateDiff(types[i], fromDate, toDate, future);
		if (diff > 0) {
			accuracy++;
			sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
		}
	}
	if (sb.length() == 0) {
		return "now";
	}
	return sb.toString().trim();
}
 
Example 8
Project: parabuild-ci   File: StatisticsUtils.java   View Source Code Vote up 6 votes
/**
   * @param date
   * @param truncateAt
   */
  public static Date truncateDate(final Date date, final int truncateAt) {
    final Calendar source = Calendar.getInstance();
    source.clear();
    source.setTime(date);
    final Calendar result = Calendar.getInstance();
    result.clear();
    result.set(Calendar.YEAR, source.get(Calendar.YEAR));
    final TimeZone sourceTimeZone = source.getTimeZone();
    result.setTimeZone(sourceTimeZone);
    if (truncateAt == Calendar.HOUR_OF_DAY) {
      result.set(Calendar.HOUR_OF_DAY, source.get(Calendar.HOUR_OF_DAY));
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
      result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
      result.set(Calendar.DST_OFFSET, source.get(Calendar.DST_OFFSET));
    } else if (truncateAt == Calendar.DAY_OF_MONTH) {
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
      result.set(Calendar.DAY_OF_MONTH, source.get(Calendar.DAY_OF_MONTH));
//      if (log.isDebugEnabled()) log.debug("result.get(Calendar.HOUR_OF_DAY): " + result.get(Calendar.HOUR_OF_DAY));
    } else if (truncateAt == Calendar.MONTH) {
      result.set(Calendar.MONTH, source.get(Calendar.MONTH));
    } else if (truncateAt == Calendar.YEAR) { // NOPMD
      // do nothing
    } else { // NOPMD
      throw new IllegalArgumentException("Unknown truncateAt");
    }
    return result.getTime();
  }
 
Example 9
Project: parabuild-ci   File: DailyPersistentTestStatsRetriever.java   View Source Code Vote up 6 votes
protected StatisticsRetrieverConfiguration getConfiguration() {
  final int rollerInitTrauncateTo = Calendar.DAY_OF_MONTH;
  final int statisticsSize = DEFAULT_STATS_DAYS;
  final int rollerStep = Calendar.DAY_OF_MONTH;
  final int cutOffBefore = Calendar.MONTH;
  return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
          statisticsSize,
          rollerStep,
          cutOffBefore);
}
 
Example 10
Project: parabuild-ci   File: HourlyPersistentBuildStatsRetriever.java   View Source Code Vote up 5 votes
protected StatisticsRetrieverConfiguration getConfiguration() {
  final int rollerInitTrauncateTo = Calendar.HOUR_OF_DAY;
  final int statisticsSize = DEFAULT_STATS_HOURS;
  final int rollerStep = Calendar.HOUR_OF_DAY;
  final int cutOffBefore = Calendar.DAY_OF_MONTH;
  return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
          statisticsSize,
          rollerStep,
          cutOffBefore);
}
 
Example 11
Project: parabuild-ci   File: DailyPersistentBuildStatsRetriever.java   View Source Code Vote up 5 votes
protected StatisticsRetrieverConfiguration getConfiguration() {
  final int rollerInitTrauncateTo = Calendar.DAY_OF_MONTH;
  final int statisticsSize = DEFAULT_STATS_DAYS;
  final int rollerStep = Calendar.DAY_OF_MONTH;
  final int cutOffBefore = Calendar.MONTH;
  return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
          statisticsSize,
          rollerStep,
          cutOffBefore);
}
 
Example 12
Project: parabuild-ci   File: HourlyPersistentTestStatsRetriever.java   View Source Code Vote up 5 votes
protected StatisticsRetrieverConfiguration getConfiguration() {
  final int rollerInitTrauncateTo = Calendar.HOUR_OF_DAY;
  final int statisticsSize = DEFAULT_STATS_HOURS;
  final int rollerStep = Calendar.HOUR_OF_DAY;
  final int cutOffBefore = Calendar.DAY_OF_MONTH;
  return new StatisticsRetrieverConfiguration(rollerInitTrauncateTo,
          statisticsSize,
          rollerStep,
          cutOffBefore);
}