Scoop API

scoop:scoop.http:0.1.0

src/cookie/date.scoop

Selected production source · src/cookie/date.scoop

1package scoop.http
3import scoop.time.Instant
5/**
6 * Cookie-date parsing, including accepted historical forms, and HTTP-date formatting.
7 */
8public object HttpCookieDate {
9 /**
10 * Parses a date or throws HttpFieldParseException when the input is invalid.
11 */
12 public fun parse(value: List<Byte>): Instant = parseCookieDate(HttpFieldReader("Expires", value))
13 /**
14 * Parses a date or throws HttpFieldParseException when the input is invalid.
15 */
16 public fun parse(value: String): Instant = parse(value.toByteArray())
17 /**
18 * Parses a date, returning None for invalid syntax or date values.
19 */
20 public fun parseOrNone(value: List<Byte>): Instant? {
21 try { return Some(parse(value)) }
22 catch (_: HttpFieldParseException) { return None }
23 }
24 /**
25 * Parses a date, returning None for invalid syntax or date values.
26 */
27 public fun parseOrNone(value: String): Instant? = parseOrNone(value.toByteArray())
28 /**
29 * Formats the instant as canonical IMF-fixdate in GMT.
30 */
31 public fun format(value: Instant): String = httpDateText(value, 1601, "Cookie date")