mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: add microsecond precision to Time struct
This commit is contained in:
@ -24,6 +24,29 @@ pub fn unix(abs int) Time {
|
||||
}
|
||||
}
|
||||
|
||||
// unix2 returns a time struct from Unix time and microsecond value
|
||||
pub fn unix2(abs int, microsecond int) Time {
|
||||
// Split into day and time
|
||||
mut day_offset := abs / seconds_per_day
|
||||
if abs % seconds_per_day < 0 {
|
||||
// Compensate for round towards zero on integers as we want floored instead
|
||||
day_offset--
|
||||
}
|
||||
year,month,day := calculate_date_from_offset(day_offset)
|
||||
hr,min,sec := calculate_time_from_offset(abs % seconds_per_day)
|
||||
return Time{
|
||||
year: year
|
||||
month: month
|
||||
day: day
|
||||
hour: hr
|
||||
minute: min
|
||||
second: sec
|
||||
microsecond: microsecond
|
||||
unix: u64(abs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[inline]
|
||||
fn calculate_date_from_offset(day_offset_ int) (int,int,int) {
|
||||
mut day_offset := day_offset_
|
||||
|
Reference in New Issue
Block a user