equal
deleted
inserted
replaced
31 new Date(ZonedDateTime.from(Formatter.try_variants(fmts, tune(str)))) |
31 new Date(ZonedDateTime.from(Formatter.try_variants(fmts, tune(str)))) |
32 } |
32 } |
33 } |
33 } |
34 |
34 |
35 def apply(pats: String*): Format = |
35 def apply(pats: String*): Format = |
36 make(pats.toList.map(Date.Formatter.pattern(_))) |
36 make(pats.toList.map(Date.Formatter.pattern)) |
37 |
37 |
38 val default: Format = Format("dd-MMM-uuuu HH:mm:ss xx") |
38 val default: Format = Format("dd-MMM-uuuu HH:mm:ss xx") |
39 val date: Format = Format("dd-MMM-uuuu") |
39 val date: Format = Format("dd-MMM-uuuu") |
40 val time: Format = Format("HH:mm:ss") |
40 val time: Format = Format("HH:mm:ss") |
41 } |
41 } |
54 def pattern(pat: String): DateTimeFormatter = DateTimeFormatter.ofPattern(pat) |
54 def pattern(pat: String): DateTimeFormatter = DateTimeFormatter.ofPattern(pat) |
55 |
55 |
56 def variants(pats: List[String], locs: List[Locale] = Nil): List[DateTimeFormatter] = |
56 def variants(pats: List[String], locs: List[Locale] = Nil): List[DateTimeFormatter] = |
57 pats.flatMap(pat => { |
57 pats.flatMap(pat => { |
58 val fmt = pattern(pat) |
58 val fmt = pattern(pat) |
59 if (locs.isEmpty) List(fmt) else locs.map(fmt.withLocale(_)) |
59 if (locs.isEmpty) List(fmt) else locs.map(fmt.withLocale) |
60 }) |
60 }) |
61 |
61 |
62 @tailrec def try_variants(fmts: List[DateTimeFormatter], str: String, |
62 @tailrec def try_variants(fmts: List[DateTimeFormatter], str: String, |
63 last_exn: Option[DateTimeParseException] = None): TemporalAccessor = |
63 last_exn: Option[DateTimeParseException] = None): TemporalAccessor = |
64 { |
64 { |