mirror of
https://github.com/vlang/v.git
synced 2025-09-09 15:27:05 -04:00
time: add a .http_header_string() method on Time (#20861)
This commit is contained in:
parent
2190b604a1
commit
38cf923537
@ -470,6 +470,14 @@ pub fn (t Time) utc_string() string {
|
|||||||
return utc_string
|
return utc_string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http_header_string returns a date string in the format used in HTTP headers, as defined in RFC 2616.
|
||||||
|
pub fn (t Time) http_header_string() string {
|
||||||
|
day_str := t.weekday_str()
|
||||||
|
month_str := t.smonth()
|
||||||
|
http_header_string := '${day_str}, ${t.day} ${month_str} ${t.year} ${t.hour:02d}:${t.minute:02d}:${t.second:02d} GMT'
|
||||||
|
return http_header_string
|
||||||
|
}
|
||||||
|
|
||||||
// mceil returns the least integer value greater than or equal to x.
|
// mceil returns the least integer value greater than or equal to x.
|
||||||
fn mceil(x f64) f64 {
|
fn mceil(x f64) f64 {
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
|
@ -86,3 +86,7 @@ fn test_get_fmt_str() {
|
|||||||
fn test_utc_string() {
|
fn test_utc_string() {
|
||||||
assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string()
|
assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_http_header_string() {
|
||||||
|
assert 'Fri, 11 Jul 1980 21:23:42 GMT' == time_to_test.http_header_string()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user