mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: remove duplicate const error; fmt: force full path to consts
This commit is contained in:
@@ -55,7 +55,7 @@ fn parse_iso8601_date(s string) ?(int, int, int) {
|
||||
year, month, day, dummy := 0, 0, 0, byte(0)
|
||||
count := unsafe { C.sscanf(charptr(s.str), '%4d-%2d-%2d%c', &year, &month, &day, &dummy) }
|
||||
if count != 3 {
|
||||
return err_invalid_8601
|
||||
return time.err_invalid_8601
|
||||
}
|
||||
return year, month, day
|
||||
}
|
||||
@@ -81,12 +81,12 @@ fn parse_iso8601_time(s string) ?(int, int, int, int, i64, bool) {
|
||||
count++ // Increment count because skipped microsecond
|
||||
}
|
||||
if count < 4 {
|
||||
return err_invalid_8601
|
||||
return time.err_invalid_8601
|
||||
}
|
||||
is_local_time := plus_min_z == `a` && count == 4
|
||||
is_utc := plus_min_z == `Z` && count == 5
|
||||
if !(count == 7 || is_local_time || is_utc) {
|
||||
return err_invalid_8601
|
||||
return time.err_invalid_8601
|
||||
}
|
||||
if plus_min_z != `+` && plus_min_z != `-` && !is_utc && !is_local_time {
|
||||
return error('Invalid 8601 format, expected `Z` or `+` or `-` as time separator')
|
||||
@@ -113,7 +113,7 @@ pub fn parse_iso8601(s string) ?Time {
|
||||
t_i := s.index('T') or { -1 }
|
||||
parts := if t_i != -1 { [s[..t_i], s[t_i + 1..]] } else { s.split(' ') }
|
||||
if !(parts.len == 1 || parts.len == 2) {
|
||||
return err_invalid_8601
|
||||
return time.err_invalid_8601
|
||||
}
|
||||
year, month, day := parse_iso8601_date(parts[0]) ?
|
||||
mut hour, mut minute, mut second, mut microsecond, mut unix_offset, mut is_local_time := 0, 0, 0, 0, i64(0), true
|
||||
|
||||
@@ -13,9 +13,9 @@ const (
|
||||
// but otherwise can be changed at will.
|
||||
absolute_zero_year = i64(-292277022399) // as i64
|
||||
seconds_per_minute = 60
|
||||
seconds_per_hour = 60 * seconds_per_minute
|
||||
seconds_per_day = 24 * seconds_per_hour
|
||||
seconds_per_week = 7 * seconds_per_day
|
||||
seconds_per_hour = 60 * time.seconds_per_minute
|
||||
seconds_per_day = 24 * time.seconds_per_hour
|
||||
seconds_per_week = 7 * time.seconds_per_day
|
||||
days_per_400_years = 365 * 400 + 97
|
||||
days_per_100_years = 365 * 100 + 24
|
||||
days_per_4_years = 365 * 4 + 1
|
||||
@@ -141,7 +141,7 @@ pub fn (t Time) smonth() string {
|
||||
return '---'
|
||||
}
|
||||
i := t.month - 1
|
||||
return months_string[i * 3..(i + 1) * 3]
|
||||
return time.months_string[i * 3..(i + 1) * 3]
|
||||
}
|
||||
|
||||
// new_time returns a time struct with calculated Unix time.
|
||||
@@ -186,12 +186,12 @@ pub fn (t Time) add(d Duration) Time {
|
||||
|
||||
// add_seconds returns a new time struct with an added number of seconds.
|
||||
pub fn (t Time) add_seconds(seconds int) Time {
|
||||
return t.add(seconds * second)
|
||||
return t.add(seconds * time.second)
|
||||
}
|
||||
|
||||
// add_days returns a new time struct with an added number of days.
|
||||
pub fn (t Time) add_days(days int) Time {
|
||||
return t.add(days * 24 * hour)
|
||||
return t.add(days * 24 * time.hour)
|
||||
}
|
||||
|
||||
// since returns a number of seconds elapsed since a given time.
|
||||
@@ -300,13 +300,13 @@ pub fn (t Time) day_of_week() int {
|
||||
// weekday_str returns the current day as a string.
|
||||
pub fn (t Time) weekday_str() string {
|
||||
i := t.day_of_week() - 1
|
||||
return days_string[i * 3..(i + 1) * 3]
|
||||
return time.days_string[i * 3..(i + 1) * 3]
|
||||
}
|
||||
|
||||
// weekday_str returns the current day as a string.
|
||||
pub fn (t Time) long_weekday_str() string {
|
||||
i := t.day_of_week() - 1
|
||||
return long_days[i]
|
||||
return time.long_days[i]
|
||||
}
|
||||
|
||||
// ticks returns a number of milliseconds elapsed since system start.
|
||||
@@ -362,7 +362,7 @@ pub fn days_in_month(month int, year int) ?int {
|
||||
return error('Invalid month: $month')
|
||||
}
|
||||
extra := if month == 2 && is_leap_year(year) { 1 } else { 0 }
|
||||
res := month_days[month - 1] + extra
|
||||
res := time.month_days[month - 1] + extra
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ fn convert_ctime(t C.tm, microsecond int) Time {
|
||||
hour: t.tm_hour
|
||||
minute: t.tm_min
|
||||
second: t.tm_sec
|
||||
microsecond: microsecond
|
||||
microsecond: time.microsecond
|
||||
unix: u64(make_unix_time(t))
|
||||
}
|
||||
}
|
||||
@@ -392,11 +392,11 @@ pub type Duration = i64
|
||||
|
||||
pub const (
|
||||
nanosecond = Duration(1)
|
||||
microsecond = Duration(1000 * nanosecond)
|
||||
millisecond = Duration(1000 * microsecond)
|
||||
second = Duration(1000 * millisecond)
|
||||
minute = Duration(60 * second)
|
||||
hour = Duration(60 * minute)
|
||||
microsecond = Duration(1000 * time.nanosecond)
|
||||
millisecond = Duration(1000 * time.microsecond)
|
||||
second = Duration(1000 * time.millisecond)
|
||||
minute = Duration(60 * time.second)
|
||||
hour = Duration(60 * time.minute)
|
||||
infinite = Duration(-1)
|
||||
)
|
||||
|
||||
@@ -419,22 +419,22 @@ pub fn (d Duration) milliseconds() i64 {
|
||||
// consider all of them in sub-one intervals
|
||||
// seconds returns the duration as a floating point number of seconds.
|
||||
pub fn (d Duration) seconds() f64 {
|
||||
sec := d / second
|
||||
nsec := d % second
|
||||
sec := d / time.second
|
||||
nsec := d % time.second
|
||||
return f64(sec) + f64(nsec) / 1e9
|
||||
}
|
||||
|
||||
// minutes returns the duration as a floating point number of minutes.
|
||||
pub fn (d Duration) minutes() f64 {
|
||||
min := d / minute
|
||||
nsec := d % minute
|
||||
min := d / time.minute
|
||||
nsec := d % time.minute
|
||||
return f64(min) + f64(nsec) / (60 * 1e9)
|
||||
}
|
||||
|
||||
// hours returns the duration as a floating point number of hours.
|
||||
pub fn (d Duration) hours() f64 {
|
||||
hr := d / hour
|
||||
nsec := d % hour
|
||||
hr := d / time.hour
|
||||
nsec := d % time.hour
|
||||
return f64(hr) + f64(nsec) / (60 * 60 * 1e9)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user