mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: add .format_ss_milli and .format_ss_micro methods
This commit is contained in:
parent
0af415fa28
commit
8f23accc4e
@ -24,6 +24,10 @@ mut:
|
|||||||
conn &C.sqlite3
|
conn &C.sqlite3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (db DB) str() string {
|
||||||
|
return 'sqlite.DB{ conn: ' + ptr_str(db.conn) + ' }'
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
pub mut:
|
pub mut:
|
||||||
vals []string
|
vals []string
|
||||||
@ -145,4 +149,3 @@ pub fn (db DB) exec_param(query string, param string) []Row {
|
|||||||
|
|
||||||
pub fn (db DB) insert<T>(x T) {
|
pub fn (db DB) insert<T>(x T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,16 @@ pub fn (t Time) format_ss() string {
|
|||||||
return t.get_fmt_str(.hyphen, .hhmmss24, .yyyymmdd)
|
return t.get_fmt_str(.hyphen, .hhmmss24, .yyyymmdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// format_ss_milli returns a date string in "YYYY-MM-DD HH:MM:SS.123" format (24h).
|
||||||
|
pub fn (t Time) format_ss_milli() string {
|
||||||
|
return t.get_fmt_str(.hyphen, .hhmmss24_milli, .yyyymmdd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// format_ss_micro returns a date string in "YYYY-MM-DD HH:MM:SS.123456" format (24h).
|
||||||
|
pub fn (t Time) format_ss_micro() string {
|
||||||
|
return t.get_fmt_str(.hyphen, .hhmmss24_micro, .yyyymmdd)
|
||||||
|
}
|
||||||
|
|
||||||
// hhmm returns a date string in "HH:MM" format (24h).
|
// hhmm returns a date string in "HH:MM" format (24h).
|
||||||
pub fn (t Time) hhmm() string {
|
pub fn (t Time) hhmm() string {
|
||||||
return t.get_fmt_time_str(.hhmm24)
|
return t.get_fmt_time_str(.hhmm24)
|
||||||
@ -97,6 +107,12 @@ pub fn (t Time) get_fmt_time_str(fmt_time FormatTime) string {
|
|||||||
.hhmmss24{
|
.hhmmss24{
|
||||||
'${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
|
'${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
|
||||||
}
|
}
|
||||||
|
.hhmmss24_milli{
|
||||||
|
'${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${(t.microsecond/1000):03d}'
|
||||||
|
}
|
||||||
|
.hhmmss24_micro{
|
||||||
|
'${t.hour:02d}:${t.minute:02d}:${t.second:02d}.${t.microsecond:06d}'
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
'unknown enumeration $fmt_time'}
|
'unknown enumeration $fmt_time'}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ pub enum FormatTime {
|
|||||||
hhmm24
|
hhmm24
|
||||||
hhmmss12
|
hhmmss12
|
||||||
hhmmss24
|
hhmmss24
|
||||||
|
hhmmss24_milli
|
||||||
|
hhmmss24_micro
|
||||||
no_time
|
no_time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ const (
|
|||||||
hour: 21
|
hour: 21
|
||||||
minute: 23
|
minute: 23
|
||||||
second: 42
|
second: 42
|
||||||
|
microsecond: 123456
|
||||||
unix: 332198622
|
unix: 332198622
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -87,6 +88,16 @@ fn test_format_ss() {
|
|||||||
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
|
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_format_ss_milli() {
|
||||||
|
assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy)
|
||||||
|
assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_format_ss_micro() {
|
||||||
|
assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy)
|
||||||
|
assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro()
|
||||||
|
}
|
||||||
|
|
||||||
fn test_smonth() {
|
fn test_smonth() {
|
||||||
month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||||
|
Loading…
Reference in New Issue
Block a user