equal
deleted
inserted
replaced
18 { |
18 { |
19 /* format */ |
19 /* format */ |
20 |
20 |
21 object Format |
21 object Format |
22 { |
22 { |
23 def make(fmts: List[DateTimeFormatter]): Format = |
23 def make(fmts: List[DateTimeFormatter], filter: String => String = s => s): Format = |
24 { |
24 { |
25 require(fmts.nonEmpty) |
25 require(fmts.nonEmpty) |
26 |
26 |
27 @tailrec def parse_first( |
27 @tailrec def parse_first( |
28 last_exn: Option[Throwable], fs: List[DateTimeFormatter], str: String): TemporalAccessor = |
28 last_exn: Option[Throwable], fs: List[DateTimeFormatter], str: String): TemporalAccessor = |
35 } |
35 } |
36 } |
36 } |
37 new Format { |
37 new Format { |
38 def apply(date: Date): String = fmts.head.format(date.rep) |
38 def apply(date: Date): String = fmts.head.format(date.rep) |
39 def parse(str: String): Date = |
39 def parse(str: String): Date = |
40 new Date(ZonedDateTime.from(parse_first(None, fmts, str))) |
40 new Date(ZonedDateTime.from(parse_first(None, fmts, filter(str)))) |
41 } |
41 } |
42 } |
42 } |
|
43 |
|
44 def make_patterns(patterns: List[String], filter: String => String = s => s): Format = |
|
45 make(patterns.toList.map(DateTimeFormatter.ofPattern(_)), filter) |
43 |
46 |
44 def apply(patterns: String*): Format = |
47 def apply(patterns: String*): Format = |
45 make(patterns.toList.map(DateTimeFormatter.ofPattern(_))) |
48 make(patterns.toList.map(DateTimeFormatter.ofPattern(_))) |
46 |
49 |
47 val default: Format = apply("dd-MMM-uuuu HH:mm:ss xx") |
50 val default: Format = apply("dd-MMM-uuuu HH:mm:ss xx") |