All Downloads are FREE. Search and download functionalities are using the official Maven repository.

caseapp.core.argparser.PlatformArgParsers.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-M8
Show newest version
package caseapp.core.argparser

import java.text.{ParseException, SimpleDateFormat}
import java.util.{Calendar, GregorianCalendar}

import caseapp.core.Error

abstract class PlatformArgParsers {

  implicit val calendar: ArgParser[Calendar] =
    SimpleArgParser.from("yyyy-MM-dd") { s =>
      val c = new GregorianCalendar

      try {
        c.setTime(PlatformArgParsers.fmt.parse(s))
        Right(c)
      } catch {
        case e: ParseException =>
          Left(Error.MalformedValue("date", Option(e.getMessage).getOrElse("")))
      }
    }

}

object PlatformArgParsers {

  private val fmt = new SimpleDateFormat("yyyy-MM-dd")

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy