From 043f6420f7433dcc6e4660f7c351b1749bb787e0 Mon Sep 17 00:00:00 2001 From: AAAA Date: Thu, 1 Apr 2021 04:04:59 -0600 Subject: [PATCH] time: extend date str formats (#9543) --- vlib/time/format.v | 2 ++ vlib/time/time.v | 2 ++ vlib/time/time_format_test.v | 2 ++ 3 files changed, 6 insertions(+) diff --git a/vlib/time/format.v b/vlib/time/format.v index 58f1eeae4a..6304cbcf67 100644 --- a/vlib/time/format.v +++ b/vlib/time/format.v @@ -126,8 +126,10 @@ pub fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate) .mmddyyyy { '${t.month:02d}|${t.day:02d}|${t.year:04d}' } .mmmd { '$month|$t.day' } .mmmdd { '$month|${t.day:02d}' } + .mmmddyy { '$month|${t.day:02d}|$year' } .mmmddyyyy { '$month|${t.day:02d}|${t.year:04d}' } .yyyymmdd { '${t.year:04d}|${t.month:02d}|${t.day:02d}' } + .yymmdd { '$year|${t.month:02d}|${t.day:02d}' } else { 'unknown enumeration $fmt_date' } } del := match fmt_dlmtr { diff --git a/vlib/time/time.v b/vlib/time/time.v index 6271ae7037..0b80b26aac 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -72,9 +72,11 @@ pub enum FormatDate { mmddyyyy mmmd mmmdd + mmmddyy mmmddyyyy no_date yyyymmdd + yymmdd } // FormatDelimiter contains different time/date delimiters. diff --git a/vlib/time/time_format_test.v b/vlib/time/time_format_test.v index eae8b0e6a1..6042cf96da 100644 --- a/vlib/time/time_format_test.v +++ b/vlib/time/time_format_test.v @@ -72,8 +72,10 @@ fn test_get_fmt_date_str() { assert '07 11 80' == time_to_test.get_fmt_date_str(.space, .mmddyy) assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmd) assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmdd) + assert 'Jul 11 80' == time_to_test.get_fmt_date_str(.space, .mmmddyy) assert 'Jul 11 1980' == time_to_test.get_fmt_date_str(.space, .mmmddyyyy) assert '1980-07-11' == time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd) + assert '80.07.11' == time_to_test.get_fmt_date_str(.dot, .yymmdd) } fn test_get_fmt_str() {