Skip to content

Commit def4535

Browse files
committed
Fix parsing -long timestamps
1 parent fc85bfa commit def4535

File tree

2 files changed

+26
-5
lines changed
  • src/AndroidClient/client/src

2 files changed

+26
-5
lines changed

src/AndroidClient/client/src/androidTest/java/net/servicestack/client/tests/UtilsTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public void test_Can_convert_MS_Guid_to_Java_UUID(){
3939

4040
assertEquals(guidStr.replaceAll("-",""), Utils.toGuidString(uuid).toUpperCase());
4141
}
42+
43+
public void test_Can_parse_pre_UnixTime(){
44+
Date date = Utils.parseDate("\\/Date(-30610224000)\\/");
45+
assertEquals(new Date(-30610224000L), date);
46+
}
4247
}

src/AndroidClient/client/src/main/java/net/servicestack/client/Utils.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static Date parseDate(String string) {
210210

211211
if (str.startsWith(wcfJsonPrefix)) {
212212
String body = splitOnLast(splitOnFirst(str, '(')[1], ')')[0];
213-
String unixTimeStr = splitOnLast(body.replace('+', '-'), '-')[0];
213+
String unixTimeStr = splitOnFirst(body.replace('+', '-'), '-', 1)[0];
214214
long unixTime = Long.parseLong(unixTimeStr);
215215
return new Date(unixTime);
216216
}
@@ -369,32 +369,48 @@ else if (parts.length == 2)
369369

370370
/*String Utils*/
371371
public static String[] splitOnFirst(String strVal, char needle) {
372+
return splitOnFirst(strVal, needle, 0);
373+
}
374+
375+
public static String[] splitOnFirst(String strVal, char needle, int start) {
372376
if (strVal == null) return new String[0];
373-
int pos = strVal.indexOf(needle);
377+
int pos = strVal.indexOf(needle, start);
374378
return pos == -1
375379
? new String[] { strVal }
376380
: new String[] { strVal.substring(0, pos), strVal.substring(pos + 1) };
377381
}
378382

379383
public static String[] splitOnFirst(String strVal, String needle) {
384+
return splitOnFirst(strVal, needle, 0);
385+
}
386+
387+
public static String[] splitOnFirst(String strVal, String needle, int start) {
380388
if (strVal == null) return new String[0];
381-
int pos = strVal.indexOf(needle);
389+
int pos = strVal.indexOf(needle, start);
382390
return pos == -1
383391
? new String[] { strVal }
384392
: new String[] { strVal.substring(0, pos), strVal.substring(pos + needle.length()) };
385393
}
386394

387395
public static String[] splitOnLast(String strVal, char needle) {
396+
return splitOnLast(strVal, needle, strVal.length());
397+
}
398+
399+
public static String[] splitOnLast(String strVal, char needle, int start) {
388400
if (strVal == null) return new String[0];
389-
int pos = strVal.lastIndexOf(needle);
401+
int pos = strVal.lastIndexOf(needle, start);
390402
return pos == -1
391403
? new String[] { strVal }
392404
: new String[] { strVal.substring(0, pos), strVal.substring(pos + 1) };
393405
}
394406

395407
public static String[] splitOnLast(String strVal, String needle) {
408+
return splitOnLast(strVal, needle, strVal.length());
409+
}
410+
411+
public static String[] splitOnLast(String strVal, String needle, int start) {
396412
if (strVal == null) return new String[0];
397-
int pos = strVal.lastIndexOf(needle);
413+
int pos = strVal.lastIndexOf(needle, start);
398414
return pos == -1
399415
? new String[] { strVal }
400416
: new String[] { strVal.substring(0, pos), strVal.substring(pos + needle.length()) };

0 commit comments

Comments
 (0)