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

time: Windows fix

This commit is contained in:
Alexander Medvednikov 2020-01-01 12:01:03 +01:00
parent 79b4a757c4
commit 2f8969c604
4 changed files with 58 additions and 26 deletions

View File

@ -72,16 +72,6 @@ fn remove_me_when_c_bug_is_fixed() {
pub struct C.time_t {
}
struct C.tm {
tm_year int
tm_mon int
tm_mday int
tm_hour int
tm_min int
tm_sec int
tm_gmtoff int // seconds
}
fn C.time(int) C.time_t
@ -98,18 +88,6 @@ pub fn random() Time {
return time.unix(rand_unix)
}
pub fn convert_ctime(t tm) Time {
return Time{
year: t.tm_year + 1900
month: t.tm_mon + 1
day: t.tm_mday
hour: t.tm_hour
minute: t.tm_min
second: t.tm_sec
unix: C.mktime(&t)
}.add_seconds(t.tm_gmtoff)
}
// format_ss returns a string for t in a given format YYYY-MM-DD HH:MM:SS in
// 24h notation
// @param

29
vlib/time/time_nix.v Normal file
View File

@ -0,0 +1,29 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module time
struct C.tm {
tm_year int
tm_mon int
tm_mday int
tm_hour int
tm_min int
tm_sec int
tm_gmtoff int // seconds
}
pub fn convert_ctime(t tm) Time {
return Time{
year: t.tm_year + 1900
month: t.tm_mon + 1
day: t.tm_mday
hour: t.tm_hour
minute: t.tm_min
second: t.tm_sec
unix: C.mktime(&t)
}.add_seconds(t.tm_gmtoff)
}

27
vlib/time/time_windows.v Normal file
View File

@ -0,0 +1,27 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module time
struct C.tm {
tm_year int
tm_mon int
tm_mday int
tm_hour int
tm_min int
tm_sec int
//tm_gmtoff int // seconds
}
pub fn convert_ctime(t tm) Time {
return Time{
year: t.tm_year + 1900
month: t.tm_mon + 1
day: t.tm_mday
hour: t.tm_hour
minute: t.tm_min
second: t.tm_sec
unix: C.mktime(&t)
}//.add_seconds(t.tm_gmtoff)
}

View File

@ -282,11 +282,9 @@ pub fn (p mut Parser) call_expr() (ast.CallExpr,types.Type) {
if p.tok.kind == .comma {
p.error('too many arguments in call to `$fn_name`')
}
// }else{
// p.error('unknown function `$fn_name`')
}
// else{
// p.error('unknown function `$fn_name`')
// }
// exit(0)
p.check(.rpar)
node := ast.CallExpr{
name: fn_name