1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi
2022-11-15 21:53:13 +08:00
committed by GitHub
parent 56239b4a23
commit 017ace6ea7
859 changed files with 7156 additions and 7135 deletions

View File

@@ -46,7 +46,7 @@ You can also parse strings to produce time.Time values,
import time
s := '2018-01-27 12:48:34'
t := time.parse(s) or { panic('failing format: $s | err: $err') }
t := time.parse(s) or { panic('failing format: ${s} | err: ${err}') }
println(t)
println(t.unix)
```
@@ -72,6 +72,6 @@ fn do_something() {
fn main() {
sw := time.new_stopwatch()
do_something()
println('Note: do_something() took: $sw.elapsed().milliseconds() ms')
println('Note: do_something() took: ${sw.elapsed().milliseconds()} ms')
}
```
```

View File

@@ -3,7 +3,7 @@ module time
fn test_days_from_unix_epoch() {
s := '2000-05-10 22:11:03'
time_test := parse(s) or {
eprintln('> failing format: $s | err: $err')
eprintln('> failing format: ${s} | err: ${err}')
assert false
return
}

View File

@@ -271,10 +271,10 @@ pub fn (t Time) custom_format(s string) string {
'Z' {
mut hours := offset() / seconds_per_hour
if hours >= 0 {
sb.write_string('+$hours')
sb.write_string('+${hours}')
} else {
hours = -hours
sb.write_string('-$hours')
sb.write_string('-${hours}')
}
}
'ZZ' {
@@ -367,13 +367,13 @@ pub fn (t Time) get_fmt_time_str(fmt_time FormatTime) string {
t.hour
}
return match fmt_time {
.hhmm12 { '$hour_:${t.minute:02d} $tp' }
.hhmm12 { '${hour_}:${t.minute:02d} ${tp}' }
.hhmm24 { '${t.hour:02d}:${t.minute:02d}' }
.hhmmss12 { '$hour_:${t.minute:02d}:${t.second:02d} $tp' }
.hhmmss12 { '${hour_}:${t.minute:02d}:${t.second:02d} ${tp}' }
.hhmmss24 { '${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 { 'unknown enumeration $fmt_time' }
else { 'unknown enumeration ${fmt_time}' }
}
}
@@ -386,17 +386,17 @@ pub fn (t Time) get_fmt_date_str(fmt_dlmtr FormatDelimiter, fmt_date FormatDate)
month := t.smonth()
year := '${(t.year % 100):02d}'
mut res := match fmt_date {
.ddmmyy { '${t.day:02d}|${t.month:02d}|$year' }
.ddmmyy { '${t.day:02d}|${t.month:02d}|${year}' }
.ddmmyyyy { '${t.day:02d}|${t.month:02d}|${t.year:04d}' }
.mmddyy { '${t.month:02d}|${t.day:02d}|$year' }
.mmddyy { '${t.month:02d}|${t.day:02d}|${year}' }
.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}' }
.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' }
.yymmdd { '${year}|${t.month:02d}|${t.day:02d}' }
else { 'unknown enumeration ${fmt_date}' }
}
del := match fmt_dlmtr {
.dot { '.' }
@@ -424,7 +424,7 @@ pub fn (t Time) get_fmt_str(fmt_dlmtr FormatDelimiter, fmt_time FormatTime, fmt_
if fmt_time != .no_time {
dstr := t.get_fmt_date_str(fmt_dlmtr, fmt_date)
tstr := t.get_fmt_time_str(fmt_time)
return '$dstr $tstr'
return '${dstr} ${tstr}'
} else {
return t.get_fmt_date_str(fmt_dlmtr, fmt_date)
}
@@ -435,7 +435,7 @@ pub fn (t Time) get_fmt_str(fmt_dlmtr FormatDelimiter, fmt_time FormatTime, fmt_
pub fn (t Time) utc_string() string {
day_str := t.weekday_str()
month_str := t.smonth()
utc_string := '$day_str, $t.day $month_str $t.year ${t.hour:02d}:${t.minute:02d}:${t.second:02d} UTC'
utc_string := '${day_str}, ${t.day} ${month_str} ${t.year} ${t.hour:02d}:${t.minute:02d}:${t.second:02d} UTC'
return utc_string
}

View File

@@ -11,7 +11,7 @@ pub struct TimeParseError {
// msg implements the `IError.msg()` method for `TimeParseError`.
pub fn (err TimeParseError) msg() string {
return 'Invalid time format code: $err.code'
return 'Invalid time format code: ${err.code}'
}
fn error_invalid_time(code int) IError {

View File

@@ -3,7 +3,7 @@ import time
fn test_parse() {
s := '2018-01-27 12:48:34'
t := time.parse(s) or {
eprintln('> failing format: $s | err: $err')
eprintln('> failing format: ${s} | err: ${err}')
assert false
return
}
@@ -24,7 +24,7 @@ fn test_parse_invalid() {
fn test_parse_rfc2822() {
s1 := 'Thu, 12 Dec 2019 06:07:45 GMT'
t1 := time.parse_rfc2822(s1) or {
eprintln('> failing format: $s1 | err: $err')
eprintln('> failing format: ${s1} | err: ${err}')
assert false
return
}
@@ -33,7 +33,7 @@ fn test_parse_rfc2822() {
assert t1.unix == 1576130865
s2 := 'Thu 12 Dec 2019 06:07:45 +0800'
t2 := time.parse_rfc2822(s2) or {
eprintln('> failing format: $s2 | err: $err')
eprintln('> failing format: ${s2} | err: ${err}')
assert false
return
}
@@ -70,7 +70,7 @@ fn test_parse_iso8601() {
]
for i, format in formats {
t := time.parse_iso8601(format) or {
eprintln('>>> failing format: $format | err: $err')
eprintln('>>> failing format: ${format} | err: ${err}')
assert false
continue
}
@@ -94,7 +94,7 @@ fn test_parse_iso8601() {
fn test_parse_iso8601_local() {
format := '2020-06-05T15:38:06.015959'
t := time.parse_iso8601(format) or {
eprintln('> failing format: $format | err: $err')
eprintln('> failing format: ${format} | err: ${err}')
assert false
return
}
@@ -132,7 +132,7 @@ fn test_parse_iso8601_invalid() {
fn test_parse_iso8601_date_only() {
format := '2020-06-05'
t := time.parse_iso8601(format) or {
eprintln('> failing format: $format | err: $err')
eprintln('> failing format: ${format} | err: ${err}')
assert false
return
}
@@ -147,7 +147,7 @@ fn test_parse_iso8601_date_only() {
fn check_invalid_date(s string) {
if date := time.parse(s) {
eprintln('invalid date: "$s" => "$date"')
eprintln('invalid date: "${s}" => "${date}"')
assert false
}
assert true
@@ -176,7 +176,7 @@ fn test_parse_rfc3339() {
for pair in pairs {
input, expected := pair[0], pair[1]
res := time.parse_rfc3339(input) or {
eprintln('>>> failing input: $input | err: $err')
eprintln('>>> failing input: ${input} | err: ${err}')
assert false
return
}

View File

@@ -162,35 +162,35 @@ pub fn (t Time) relative() string {
if secs < time.seconds_per_hour {
m := secs / time.seconds_per_minute
if m == 1 {
return '${prefix}1 minute$suffix'
return '${prefix}1 minute${suffix}'
}
return '$prefix$m minutes$suffix'
return '${prefix}${m} minutes${suffix}'
}
if secs < time.seconds_per_hour * 24 {
h := secs / time.seconds_per_hour
if h == 1 {
return '${prefix}1 hour$suffix'
return '${prefix}1 hour${suffix}'
}
return '$prefix$h hours$suffix'
return '${prefix}${h} hours${suffix}'
}
if secs < time.seconds_per_hour * 24 * 7 {
d := secs / time.seconds_per_hour / 24
if d == 1 {
return '${prefix}1 day$suffix'
return '${prefix}1 day${suffix}'
}
return '$prefix$d days$suffix'
return '${prefix}${d} days${suffix}'
}
if secs < time.seconds_per_hour * 24 * time.days_in_year {
if prefix == 'in ' {
return 'on $t.md()'
return 'on ${t.md()}'
}
return 'last $t.md()'
return 'last ${t.md()}'
}
y := secs / time.seconds_per_hour / 24 / time.days_in_year
if y == 1 {
return '${prefix}1 year$suffix'
return '${prefix}1 year${suffix}'
}
return '$prefix$y years$suffix'
return '${prefix}${y} years${suffix}'
}
// relative_short returns a string saying how long ago a time occured as follows:
@@ -224,29 +224,29 @@ pub fn (t Time) relative_short() string {
if secs < time.seconds_per_hour {
m := secs / time.seconds_per_minute
if m == 1 {
return '${prefix}1m$suffix'
return '${prefix}1m${suffix}'
}
return '$prefix${m}m$suffix'
return '${prefix}${m}m${suffix}'
}
if secs < time.seconds_per_hour * 24 {
h := secs / time.seconds_per_hour
if h == 1 {
return '${prefix}1h$suffix'
return '${prefix}1h${suffix}'
}
return '$prefix${h}h$suffix'
return '${prefix}${h}h${suffix}'
}
if secs < time.seconds_per_hour * 24 * time.days_in_year {
d := secs / time.seconds_per_hour / 24
if d == 1 {
return '${prefix}1d$suffix'
return '${prefix}1d${suffix}'
}
return '$prefix${d}d$suffix'
return '${prefix}${d}d${suffix}'
}
y := secs / time.seconds_per_hour / 24 / time.days_in_year
if y == 1 {
return '${prefix}1y$suffix'
return '${prefix}1y${suffix}'
}
return '$prefix${y}y$suffix'
return '${prefix}${y}y${suffix}'
}
// day_of_week returns the current day of a given year, month, and day,
@@ -287,7 +287,7 @@ pub fn is_leap_year(year int) bool {
// days_in_month returns a number of days in a given month.
pub fn days_in_month(month int, year int) ?int {
if month > 12 || month < 1 {
return error('Invalid month: $month')
return error('Invalid month: ${month}')
}
extra := if month == 2 && is_leap_year(year) { 1 } else { 0 }
res := time.month_days[month - 1] + extra
@@ -378,10 +378,10 @@ pub fn (d Duration) str() string {
ns := t
if hr > 0 {
return '$hr:${min:02}:${sec:02}'
return '${hr}:${min:02}:${sec:02}'
}
if min > 0 {
return '$min:${sec:02}.${ms:03}'
return '${min}:${sec:02}.${ms:03}'
}
if sec > 0 {
return '${sec}.${ms:03}s'

View File

@@ -210,18 +210,18 @@ fn test_unix_time() {
t1 := time.utc()
time.sleep(50 * time.millisecond)
t2 := time.utc()
eprintln('t1: $t1')
eprintln('t2: $t2')
eprintln('t1: ${t1}')
eprintln('t2: ${t2}')
ut1 := t1.unix_time()
ut2 := t2.unix_time()
eprintln('ut1: $ut1')
eprintln('ut2: $ut2')
eprintln('ut1: ${ut1}')
eprintln('ut2: ${ut2}')
assert ut2 - ut1 < 2
//
utm1 := t1.unix_time_milli()
utm2 := t2.unix_time_milli()
eprintln('utm1: $utm1')
eprintln('utm2: $utm2')
eprintln('utm1: ${utm1}')
eprintln('utm2: ${utm2}')
assert (utm1 - ut1 * 1000) < 1000
assert (utm2 - ut2 * 1000) < 1000
//