@@ -60,7 +60,23 @@ protected String getResourceLocation() {
6060 return "/" + TwilioRestClient .DEFAULT_VERSION + "/Accounts/"
6161 + this .getRequestAccountSid () + "/SMS/Messages/" + this .getSid () + ".json" ;
6262 }
63-
63+ /**
64+ * return a date from the property string
65+ *
66+ * @return the date value of the input string
67+ */
68+ protected Date parseDate (String inDate ) {
69+ if (inDate ==null ) {
70+ return null ;
71+ }
72+ SimpleDateFormat format = new SimpleDateFormat (
73+ "EEE, dd MMM yyyy HH:mm:ss Z" );
74+ try {
75+ return format .parse (inDate );
76+ } catch (ParseException e ) {
77+ return null ;
78+ }
79+ }
6480 /*
6581 * Property getters
6682 */
@@ -79,13 +95,7 @@ public String getSid() {
7995 * @return the date created
8096 */
8197 public Date getDateCreated () {
82- SimpleDateFormat format = new SimpleDateFormat (
83- "EEE, dd MMM yyyy HH:mm:ss Z" );
84- try {
85- return format .parse (this .getProperty ("date_created" ));
86- } catch (ParseException e ) {
87- return null ;
88- }
98+ return parseDate (this .getProperty ("date_created" ));
8999 }
90100
91101 /**
@@ -94,13 +104,7 @@ public Date getDateCreated() {
94104 * @return the date updated
95105 */
96106 public Date getDateUpdated () {
97- SimpleDateFormat format = new SimpleDateFormat (
98- "EEE, dd MMM yyyy HH:mm:ss Z" );
99- try {
100- return format .parse (this .getProperty ("date_updated" ));
101- } catch (ParseException e ) {
102- return null ;
103- }
107+ return parseDate (this .getProperty ("date_updated" ));
104108 }
105109
106110 /**
@@ -109,13 +113,7 @@ public Date getDateUpdated() {
109113 * @return the date sent
110114 */
111115 public Date getDateSent () {
112- SimpleDateFormat format = new SimpleDateFormat (
113- "EEE, dd MMM yyyy HH:mm:ss Z" );
114- try {
115- return format .parse (this .getProperty ("date_sent" ));
116- } catch (ParseException e ) {
117- return null ;
118- }
116+ return parseDate (this .getProperty ("date_sent" ));
119117 }
120118
121119 /**
@@ -189,5 +187,5 @@ public String getDirection() {
189187 public String getApiVersion () {
190188 return this .getProperty ("api_version" );
191189 }
192-
190+
193191}
0 commit comments