use of io.jans.scim.model.scim2.util.DateUtil in project CodenameOne by codenameone.
the class SimpleDateFormat method format.
@Override
String format(Date source, StringBuilder toAppendTo) {
if (pattern == null) {
return super.format(source, toAppendTo);
}
// format based on local timezone
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
calendar.setTime(source);
List<String> pattern = getPatternTokens();
for (int i = 0; i < pattern.size(); i++) {
String token = (String) pattern.get(i);
char patternChar = token.charAt(0);
token = token.substring(1);
int len = token.length();
int v = -1;
switch(patternChar) {
case LITERAL_LETTER:
toAppendTo.append(token);
break;
case AMPM_LETTER:
boolean am = calendar.get(Calendar.AM_PM) == Calendar.AM;
String[] ampm = getDateFormatSymbols().getAmPmStrings();
toAppendTo.append(am ? ampm[0] : ampm[1]);
break;
case ERA_LETTER:
toAppendTo.append(getDateFormatSymbols().getEras()[calendar.get(ERA)]);
break;
case DAY_OF_WEEK_LETTER:
v = calendar.get(Calendar.DAY_OF_WEEK) - 1;
if (len > 3) {
toAppendTo.append(getDateFormatSymbols().getWeekdays()[v]);
} else {
toAppendTo.append(getDateFormatSymbols().getShortWeekdays()[v]);
}
break;
case TIMEZONE_LETTER:
String[] names = getTimeZoneDisplayNames(calendar.getTimeZone().getID());
if (names == null) {
toAppendTo.append(calendar.getTimeZone().getID());
} else {
DateUtil du = new DateUtil(TimeZone.getTimeZone(names[DateFormatSymbols.ZONE_ID]));
toAppendTo.append(names[du.inDaylightTime(source) ? DateFormatSymbols.ZONE_SHORTNAME_DST : DateFormatSymbols.ZONE_SHORTNAME]);
}
break;
case TIMEZONE822_LETTER:
v = getOffsetInMinutes(calendar, calendar.getTimeZone());
if (v < 0) {
toAppendTo.append(SIGN_NEGATIVE);
v = -v;
} else {
toAppendTo.append(SIGN_POSITIVE);
}
toAppendTo.append(leftPad(v / 60, 2));
toAppendTo.append(leftPad(v % 60, 2));
break;
case YEAR_LETTER:
v = calendar.get(Calendar.YEAR);
if (len == 2) {
v %= 100;
}
toAppendTo.append(leftPad(v, len));
break;
case MONTH_LETTER:
v = calendar.get(Calendar.MONTH) - Calendar.JANUARY;
if (len > 3) {
toAppendTo.append(L10NManager.getInstance().getLongMonthName(source));
} else if (len == 3) {
toAppendTo.append(L10NManager.getInstance().getShortMonthName(source));
} else {
toAppendTo.append(leftPad(v + 1, len));
}
break;
case DAY_LETTER:
v = calendar.get(Calendar.DAY_OF_MONTH);
toAppendTo.append(leftPad(v, len));
break;
case HOUR_LETTER:
case HOUR_1_LETTER:
case HOUR12_LETTER:
case HOUR12_1_LETTER:
v = calendar.get(Calendar.HOUR_OF_DAY);
if (patternChar == HOUR_1_LETTER && v == 0) {
v = 24;
}
if (patternChar == HOUR12_1_LETTER) {
v %= 12;
if (v == 0) {
v = 12;
}
} else {
if (patternChar == HOUR12_LETTER) {
v %= 12;
}
}
toAppendTo.append(leftPad(v, len));
break;
case MINUTE_LETTER:
v = calendar.get(Calendar.MINUTE);
toAppendTo.append(leftPad(v, len));
break;
case SECOND_LETTER:
v = calendar.get(Calendar.SECOND);
toAppendTo.append(leftPad(v, len));
break;
case MILLISECOND_LETTER:
v = calendar.get(Calendar.MILLISECOND);
toAppendTo.append(leftPad(v, len));
break;
case WEEK_IN_YEAR_LETTER:
v = calendar.get(WEEK_OF_YEAR);
toAppendTo.append(leftPad(v, len));
break;
case WEEK_IN_MONTH_LETTER:
v = calendar.get(WEEK_OF_MONTH);
toAppendTo.append(leftPad(v, len));
break;
case DAY_IN_YEAR_LETTER:
v = calendar.get(DAY_OF_YEAR);
toAppendTo.append(leftPad(v, len));
break;
case DOW_IN_MONTH_LETTER:
v = calendar.get(DAY_OF_WEEK_IN_MONTH);
toAppendTo.append(leftPad(v, len));
break;
}
}
return toAppendTo.toString();
}
use of io.jans.scim.model.scim2.util.DateUtil in project jans by JanssenProject.
the class PatchUserExtTest method patchObject.
@Test(dependsOnMethods = "patchJson")
public void patchObject() {
PatchOperation operation = new PatchOperation();
operation.setOperation("replace");
operation.setPath("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond");
long now = System.currentTimeMillis();
List<String> someDates = Arrays.asList(now, now + 1000, now + 2000, now + 3000).stream().map(DateUtil::millisToISOString).collect(Collectors.toList());
operation.setValue(someDates);
PatchRequest pr = new PatchRequest();
pr.setOperations(Collections.singletonList(operation));
Response response = client.patchUser(pr, user.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
UserResource other = response.readEntity(usrClass);
CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
// Verify different dates appeared in scimCustomSecond
List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
assertEquals(scimCustomSecond.size(), someDates.size());
assertEquals(now, scimCustomSecond.get(0).getTime());
}
Aggregations