1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

Fix bday generation

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1234 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-20 16:02:59 +00:00
parent 9ce38ae715
commit 8ed3ee021d
2 changed files with 21 additions and 7 deletions

View File

@ -119,6 +119,7 @@ public abstract class ExchangeSession {
private static final String YYYY_MM_DD_HH_MM_SS = "yyyy/MM/dd HH:mm:ss";
private static final String YYYYMMDD_T_HHMMSS_Z = "yyyyMMdd'T'HHmmss'Z'";
private static final String YYYY_MM_DD_T_HHMMSS_Z = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String YYYY_MM_DD = "yyyy-MM-dd";
private static final String YYYY_MM_DD_T_HHMMSS_SSS_Z = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
/**
@ -203,6 +204,12 @@ public abstract class ExchangeSession {
return dateFormat;
}
protected static SimpleDateFormat getVcardBdayFormat() {
SimpleDateFormat dateFormat = new SimpleDateFormat(YYYY_MM_DD, Locale.ENGLISH);
dateFormat.setTimeZone(GMT_TIMEZONE);
return dateFormat;
}
protected static SimpleDateFormat getExchangeZuluDateFormat() {
SimpleDateFormat dateFormat = new SimpleDateFormat(YYYY_MM_DD_T_HHMMSS_Z, Locale.ENGLISH);
dateFormat.setTimeZone(GMT_TIMEZONE);
@ -1724,8 +1731,16 @@ public abstract class ExchangeSession {
writer.appendProperty("ROLE", get("profession"));
writer.appendProperty("NICKNAME", get("nickname"));
writer.appendProperty("X-AIM", get("im"));
writer.appendProperty("BDAY", get("bday"));
// convert bday value
String bday = get("bday");
if (bday != null && bday.length() > 0) {
try {
SimpleDateFormat parser = ExchangeSession.getZuluDateFormat();
writer.appendProperty("BDAY", ExchangeSession.getVcardBdayFormat().format(parser.parse(bday)));
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + bday);
}
}
writer.appendProperty("CATEGORIES", get("keywords"));
@ -2761,10 +2776,9 @@ public abstract class ExchangeSession {
try {
SimpleDateFormat parser;
if (value.length() == 10) {
parser = new SimpleDateFormat("yyyy-MM-dd");
parser.setTimeZone(GMT_TIMEZONE);
parser = ExchangeSession.getVcardBdayFormat();
} else {
parser = ExchangeSession.getZuluDateFormat();
parser = ExchangeSession.getExchangeZuluDateFormat();
}
properties.put("bday", ExchangeSession.getExchangeZuluDateFormatMillisecond().format(parser.parse(value)));
} catch (ParseException e) {

View File

@ -86,7 +86,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
vCardWriter.appendProperty("ROLE", "profession");
vCardWriter.appendProperty("X-AIM", "im");
vCardWriter.appendProperty("BDAY", "20000102T000000Z");
vCardWriter.appendProperty("BDAY", "2000-01-02T00:00:00Z");
vCardWriter.appendProperty("CATEGORIES", "keyword1,keyword2");
vCardWriter.appendProperty("X-ASSISTANT", "secretarycn");
@ -421,6 +421,6 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
contact = getCurrentContact();
assertEquals("20000102T000000Z", contact.get("bday"));
System.out.println(contact.getBody());
}
}