Skip to content

Commit

Permalink
update event_time (SimpleEvent_V1.scala), add date utils
Browse files Browse the repository at this point in the history
  • Loading branch information
yennan.liu committed Apr 27, 2021
1 parent b9188f9 commit 99e4de0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.yen.eventCreator
import java.io.PrintWriter
import java.net.ServerSocket
import java.util.Random
import java.time.LocalDateTime
import java.time.{LocalDateTime, LocalTime}

import com.google.gson.Gson

Expand All @@ -27,7 +27,7 @@ object SimpleEvent_V1 extends App {
val listener = new ServerSocket(port)
println(s"Listening on port: $port")

case class simpleEvent(id: Int, event_date: Long, msg: String)
case class simpleEvent(id: Int, event_date: String, msg: String)

while (true) {
val socket = listener.accept()
Expand All @@ -40,7 +40,8 @@ object SimpleEvent_V1 extends App {

val r = scala.util.Random
val id = r.nextInt(10000000)
val event_date = System.currentTimeMillis
//val event_date = System.currentTimeMillis
val event_date = LocalDateTime.now()

val someRandom = r.nextInt(10)

Expand All @@ -50,7 +51,7 @@ object SimpleEvent_V1 extends App {
case _ => "wazzup ?"
}

val payload = new simpleEvent(id, event_date, msg)
val payload = new simpleEvent(id, event_date.toString, msg)

Thread.sleep(sleepDelayMs)
val msgDataJson = new Gson().toJson(payload)
Expand Down
18 changes: 18 additions & 0 deletions spark/src/main/scala/com/yen/utils/DateUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.yen.utils

import org.joda.time.{DateTime, DateTimeZone}
import org.joda.time.format.{DateTimeFormat, DateTimeFormatter, ISODateTimeFormat}

object DateUtils {
// datetime format
val yyyyMMFormat: DateTimeFormatter = DateTimeFormat.forPattern("yyyyMM")
val yyyyMMddFormat: DateTimeFormatter = DateTimeFormat.forPattern("yyyyMMdd")
val yyyyMMddHHFormat: DateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHH")

// time zone
val dateFormatTaipei: DateTimeFormatter = DateTimeFormat.forPattern("yyyyMMdd").withZone(DateTimeZone.forID("Asia/Taipei"))

// iso time
val ISO8601Format: DateTimeFormatter = ISODateTimeFormat.dateTime()
}

0 comments on commit 99e4de0

Please sign in to comment.