Skip to content

Commit

Permalink
Merge pull request apache#63 from Shopify/kevincox-spark-timestamp
Browse files Browse the repository at this point in the history
"Fix" timestamp parsing and update spark.
  • Loading branch information
kevincox committed Aug 24, 2015
2 parents 5c6b2b1 + 1f41ea1 commit f7b4551
Showing 1 changed file with 8 additions and 17 deletions.
Expand Up @@ -107,30 +107,21 @@ object DateTimeUtils {
}

def stringToTime(s: String): java.util.Date = {
if (!s.contains('T')) {
var indexOfGMT = s.indexOf("GMT");
if (indexOfGMT != -1) {
// timezone with ISO8601
val s0 = s.substring(0, indexOfGMT)
val s1 = s.substring(indexOfGMT + 3)
return stringToTime(s0 + s1)
} else if (!s.contains('T')) {
// JDBC escape string
if (s.contains(' ')) {
Timestamp.valueOf(s)
} else {
Date.valueOf(s)
}
} else if (s.endsWith("Z")) {
// this is zero timezone of ISO8601
stringToTime(s.substring(0, s.length - 1) + "GMT-00:00")
} else if (s.indexOf("GMT") == -1) {
// timezone with ISO8601
val inset = "+00.00".length
val s0 = s.substring(0, s.length - inset)
val s1 = s.substring(s.length - inset, s.length)
if (s0.substring(s0.lastIndexOf(':')).contains('.')) {
stringToTime(s0 + "GMT" + s1)
} else {
stringToTime(s0 + ".0GMT" + s1)
}
} else {
// ISO8601 with GMT insert
val ISO8601GMT: SimpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSz" )
ISO8601GMT.parse(s)
javax.xml.bind.DatatypeConverter.parseDateTime(s).getTime()
}
}

Expand Down

0 comments on commit f7b4551

Please sign in to comment.