Skip to content

Commit

Permalink
Added file parts for hour, minute, and second
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Mar 8, 2022
1 parent 8586e54 commit f0af247
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fileModule/shared/src/main/scala/scribe/file/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package object file {
implicit def string2FileNamePart(s: String): FileNamePart = FileNamePart.Static(s)
implicit def fileNamePart2FileName(part: FileNamePart): FileName = FileName(List(part))

def second: FileNamePart = FileNamePart.Second
def minute: FileNamePart = FileNamePart.Minute
def hour: FileNamePart = FileNamePart.Hour
def day: FileNamePart = FileNamePart.Day
def month: FileNamePart = FileNamePart.Month
def year: FileNamePart = FileNamePart.Year
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,49 @@ object FileNamePart {
Some(c.getTimeInMillis)
}
}

case object Hour extends FileNamePart {
override def current(timeStamp: Long): String = timeStamp.t.H

override def regex: String = "\\d{2}"

override def nextValidation(timeStamp: Long): Option[Long] = {
val c = Calendar.getInstance()
c.setTimeInMillis(timeStamp)
c.add(Calendar.HOUR_OF_DAY, 1)
c.set(Calendar.MINUTE, 0)
c.set(Calendar.SECOND, 0)
c.set(Calendar.MILLISECOND, 0)
Some(c.getTimeInMillis)
}
}

case object Minute extends FileNamePart {
override def current(timeStamp: Long): String = timeStamp.t.M

override def regex: String = "\\d{2}"

override def nextValidation(timeStamp: Long): Option[Long] = {
val c = Calendar.getInstance()
c.setTimeInMillis(timeStamp)
c.add(Calendar.MINUTE, 1)
c.set(Calendar.SECOND, 0)
c.set(Calendar.MILLISECOND, 0)
Some(c.getTimeInMillis)
}
}

case object Second extends FileNamePart {
override def current(timeStamp: Long): String = timeStamp.t.S

override def regex: String = "\\d{2}"

override def nextValidation(timeStamp: Long): Option[Long] = {
val c = Calendar.getInstance()
c.setTimeInMillis(timeStamp)
c.add(Calendar.SECOND, 1)
c.set(Calendar.MILLISECOND, 0)
Some(c.getTimeInMillis)
}
}
}

0 comments on commit f0af247

Please sign in to comment.