All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.vvcephei.scalaofx.lib.message.Util.scala Maven / Gradle / Ivy
package org.vvcephei.scalaofx.lib.message
import org.joda.time.{DateTimeZone, DateTime}
import org.joda.time.format.DateTimeFormat
import java.util.UUID
object Util {
def trnuid() = UUID.randomUUID().toString.toUpperCase
private lazy val df = DateTimeFormat.forPattern("YYYYMMdd")
def toDateString(date: DateTime): String = df print date
def fromDateString(date: String): DateTime = df.withZone(DateTimeZone.UTC) parseDateTime date
private lazy val dtf = DateTimeFormat.forPattern("YYYYMMddHHmmss.SSS")
private lazy val dtfNoFracSec = DateTimeFormat.forPattern("YYYYMMddHHmmss")
def toDateTimeString(dateTime: DateTime): String = dtf print dateTime
def fromDateTimeString(dateTime: String): DateTime = dtf.withZone(DateTimeZone.UTC) parseDateTime dateTime
def fromDateTimeZoneString(dateTime: String, zone: DateTimeZone): DateTime = dtf.withZone(zone) parseDateTime dateTime
def fromDateTimeStringNoFracSec(dateTime: String): DateTime = dtfNoFracSec.withZone(DateTimeZone.UTC) parseDateTime dateTime
def fromDateTimeZoneStringNoFracSec(dateTime: String, zone: DateTimeZone): DateTime = dtfNoFracSec.withZone(zone) parseDateTime dateTime
private val dt = """(\d{8})(\d{6})?(\.\d{3})?(\[([^:]+)?:([^\]]+)?\])?""".r("date", "time?", "milli?", "zonegroup?", "zone:offset?", "zone:name?")
def dateFromStringInferred(dateTime: String): DateTime = dateTime match {
case dt(date, null, null, _, null, _) => fromDateString(date)
case dt(date, time, null, _, null, _) => fromDateTimeStringNoFracSec(date + time)
case dt(date, time, milli, _, null, _) => fromDateTimeString(date + time + milli)
case dt(date, time, null, _, offset, _) => fromDateTimeZoneStringNoFracSec(date + time, DateTimeZone.forOffsetHours(offset.toInt))
case dt(date, time, milli, _, offset, _) => fromDateTimeZoneString(date + time + milli, DateTimeZone.forOffsetHours(offset.toInt))
}
}