Code example for GregorianCalendar

Methods: add, get, getTime, set

0
    return new TypeValuePair(DateTimeType.DATE_TYPE, date);
  } 
 
  private static Date prevweekday(final int type, final LocalizationContext context)
  { 
    final GregorianCalendar gc = new GregorianCalendar(context.getTimeZone(),
        context.getLocale());
    gc.set(Calendar.MILLISECOND, 0);
    final int dayOfWeek = gc.get(Calendar.DAY_OF_WEEK);
    if (type == 1)
    { /*  weekend = saturday + sunday */ 
      if (dayOfWeek == Calendar.SUNDAY)
      { 
        gc.add(Calendar.DAY_OF_MONTH, -2);
      } 
      else if (dayOfWeek == Calendar.MONDAY)
      { 
        gc.add(Calendar.DAY_OF_MONTH, -3);
      } 
      else 
      { 
        gc.add(Calendar.DAY_OF_MONTH, -1);
      } 
    } 
    else 
    { /* weekend = friday + saturday */ 
      if (dayOfWeek == Calendar.SATURDAY)
      { 
        gc.add(Calendar.DAY_OF_MONTH, -2);
      } 
      else if (dayOfWeek == Calendar.SUNDAY)
      { 
        gc.add(Calendar.DAY_OF_MONTH, -3);
      } 
      else 
      { 
        gc.add(Calendar.DAY_OF_MONTH, -1);
      } 
    } 
 
    return gc.getTime();
  } 
 
}