| 1 | import time |
| 2 | |
| 3 | const time_to_test = time.Time{ |
| 4 | year: 1980 |
| 5 | month: 7 |
| 6 | day: 11 |
| 7 | hour: 21 |
| 8 | minute: 23 |
| 9 | second: 42 |
| 10 | } |
| 11 | |
| 12 | fn test_now_format() { |
| 13 | t := time.now() |
| 14 | u := t.unix() |
| 15 | assert t.format() == time.unix(int(u)).utc_to_local().format() |
| 16 | } |
| 17 | |
| 18 | fn test_format() { |
| 19 | assert '11.07.1980 21:23' == time_to_test.get_fmt_str(.dot, .hhmm24, .ddmmyyyy) |
| 20 | } |
| 21 | |
| 22 | fn test_hhmm() { |
| 23 | assert '21:23' == time_to_test.hhmm() |
| 24 | } |
| 25 | |
| 26 | fn test_hhmm12() { |
| 27 | assert '9:23 p.m.' == time_to_test.hhmm12() |
| 28 | } |
| 29 | |
| 30 | fn test_hhmmss() { |
| 31 | assert '21:23:42' == time_to_test.hhmmss() |
| 32 | } |
| 33 | |
| 34 | fn test_ymmdd() { |
| 35 | assert '1980-07-11' == time_to_test.ymmdd() |
| 36 | } |
| 37 | |
| 38 | fn test_ddmmy() { |
| 39 | assert '11.07.1980' == time_to_test.ddmmy() |
| 40 | } |
| 41 | |
| 42 | fn test_md() { |
| 43 | assert 'Jul 11' == time_to_test.md() |
| 44 | } |
| 45 | |
| 46 | fn test_get_fmt_time_str() { |
| 47 | assert '21:23:42' == time_to_test.get_fmt_time_str(.hhmmss24) |
| 48 | assert '21:23' == time_to_test.get_fmt_time_str(.hhmm24) |
| 49 | assert '9:23:42 p.m.' == time_to_test.get_fmt_time_str(.hhmmss12) |
| 50 | assert '9:23 p.m.' == time_to_test.get_fmt_time_str(.hhmm12) |
| 51 | } |
| 52 | |
| 53 | fn test_get_fmt_date_str() { |
| 54 | assert '11.07.1980' == time_to_test.get_fmt_date_str(.dot, .ddmmyyyy) |
| 55 | assert '11/07/1980' == time_to_test.get_fmt_date_str(.slash, .ddmmyyyy) |
| 56 | assert '11-07-1980' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyyyy) |
| 57 | assert '11 07 1980' == time_to_test.get_fmt_date_str(.space, .ddmmyyyy) |
| 58 | assert '07.11.1980' == time_to_test.get_fmt_date_str(.dot, .mmddyyyy) |
| 59 | assert '07/11/1980' == time_to_test.get_fmt_date_str(.slash, .mmddyyyy) |
| 60 | assert '07-11-1980' == time_to_test.get_fmt_date_str(.hyphen, .mmddyyyy) |
| 61 | assert '07 11 1980' == time_to_test.get_fmt_date_str(.space, .mmddyyyy) |
| 62 | assert '11.07.80' == time_to_test.get_fmt_date_str(.dot, .ddmmyy) |
| 63 | assert '11/07/80' == time_to_test.get_fmt_date_str(.slash, .ddmmyy) |
| 64 | assert '11-07-80' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyy) |
| 65 | assert '11 07 80' == time_to_test.get_fmt_date_str(.space, .ddmmyy) |
| 66 | assert '07.11.80' == time_to_test.get_fmt_date_str(.dot, .mmddyy) |
| 67 | assert '07/11/80' == time_to_test.get_fmt_date_str(.slash, .mmddyy) |
| 68 | assert '07-11-80' == time_to_test.get_fmt_date_str(.hyphen, .mmddyy) |
| 69 | assert '07 11 80' == time_to_test.get_fmt_date_str(.space, .mmddyy) |
| 70 | assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmd) |
| 71 | assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmdd) |
| 72 | assert 'Jul 11 80' == time_to_test.get_fmt_date_str(.space, .mmmddyy) |
| 73 | assert 'Jul 11 1980' == time_to_test.get_fmt_date_str(.space, .mmmddyyyy) |
| 74 | assert '1980-07-11' == time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd) |
| 75 | assert '80.07.11' == time_to_test.get_fmt_date_str(.dot, .yymmdd) |
| 76 | } |
| 77 | |
| 78 | fn test_get_fmt_str() { |
| 79 | // Since get_fmt_time_str and get_fmt_date_str do have comprehensive |
| 80 | // tests I don't want to exaggerate here with all possible |
| 81 | // combinations. |
| 82 | assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy) |
| 83 | } |
| 84 | |
| 85 | fn test_utc_string() { |
| 86 | assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string() |
| 87 | } |
| 88 | |
| 89 | fn test_http_header_string() { |
| 90 | assert 'Fri, 11 Jul 1980 21:23:42 GMT' == time_to_test.http_header_string() |
| 91 | } |
| 92 | |
| 93 | fn test_push_to_http_header() { |
| 94 | mut http1_1_buffer := 'HTTP/1.1 200 OK\r\nDate: '.bytes() |
| 95 | time_to_test.push_to_http_header(mut http1_1_buffer) |
| 96 | |
| 97 | assert http1_1_buffer.bytestr() == 'HTTP/1.1 200 OK\r\nDate: Fri, 11 Jul 1980 21:23:42 GMT' |
| 98 | } |
| 99 | |