code: public static DateTimeValue parse(Calendar cal, DateTimeType type) {
  
  		int sYear = 0;
  		int sMonthDay = 0;
  		int sTime = 0;
  		int sFractionalSecs = 0;
  		boolean sPresenceTimezone = false;
  		int sTimezone;
  
  		switch (type) {
  		case gYear: // gYear Year, [Time-Zone]
  		case gYearMonth: // gYearMonth Year, MonthDay, [TimeZone]
  		case date: // date Year, MonthDay, [TimeZone]
  			sYear = cal.get(Calendar.YEAR);
  			sMonthDay = getMonthDay(cal);
  			break;
  		case dateTime: // dateTime Year, MonthDay, Time, [FractionalSecs],
  			// [TimeZone]
  			sYear = cal.get(Calendar.YEAR);
  			sMonthDay = getMonthDay(cal);
  			// Note: *no* break;
  		case time: // time Time, [FractionalSecs], [TimeZone]
  			sTime = getTime(cal);
  			sFractionalSecs = cal.get(Calendar.MILLISECOND);
  			break;
  		case gMonth: // gMonth MonthDay, [TimeZone]
  		case gMonthDay: // gMonthDay MonthDay, [TimeZone]
  		case gDay: // gDay MonthDay, [TimeZone]
  			sMonthDay = getMonthDay(cal);
  			break;
  		default:
  			throw new UnsupportedOperationException();
  		}
  		// [TimeZone]
  		sTimezone = getTimeZoneInMinutesOffset(cal);
  		if (sTimezone != 0) {
  			sPresenceTimezone = true;
  		}
  
  		return new DateTimeValue(type, sYear, sMonthDay, sTime,
  				sFractionalSecs, sPresenceTimezone, sTimezone);
  	}
docs: Encode Date-Time as a sequence of values representing the individual
  components of the Date-Time.
  
  @param cal
  calendar
  @param type
  date-time type
  @return date-time value