scoop:scoop.http:0.1.0
src/cookie/date.scoop
Selected production source · src/cookie/date.scoop
1
package scoop.http3
import scoop.time.Instant5
/**6
* Cookie-date parsing, including accepted historical forms, and HTTP-date formatting.7
*/8
public 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")32
}