Skip to content

Commit

Permalink
update unix time access
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 9, 2024
1 parent 6a8fa76 commit 990a8c2
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion vlib/db/mysql/orm.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn stmt_bind_primitive(mut stmt Stmt, data orm.Primitive) {
stmt.bind_text(data)
}
time.Time {
unix := int(data.unix)
unix := int(data.unix_time())
stmt_bind_primitive(mut stmt, unix)
}
orm.InfixType {
Expand Down
2 changes: 1 addition & 1 deletion vlib/db/sqlite/orm.v
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn bind(stmt Stmt, c &int, data orm.Primitive) int {
err = stmt.bind_text(c, data)
}
time.Time {
err = stmt.bind_int(c, int(data.unix))
err = stmt.bind_int(c, int(data.unix_time()))
}
orm.InfixType {
err = bind(stmt, c, data.right)
Expand Down
2 changes: 1 addition & 1 deletion vlib/net/openssl/ssl_connection.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn (mut s SSLConn) init() ! {
mut cert := s.config.cert
mut cert_key := s.config.cert_key
if s.config.in_memory_verification {
now := time.now().unix.str()
now := time.now().unix_time().str()
verify = os.temp_dir() + '/v_verify' + now
cert = os.temp_dir() + '/v_cert' + now
cert_key = os.temp_dir() + '/v_cert_key' + now
Expand Down
6 changes: 3 additions & 3 deletions vlib/net/tcp.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn (c TcpConn) read(mut buf []u8) !int {
}

pub fn (mut c TcpConn) read_deadline() !time.Time {
if c.read_deadline.unix == 0 {
if c.read_deadline.unix_time() == 0 {
return c.read_deadline
}
return error('none')
Expand Down Expand Up @@ -246,7 +246,7 @@ pub fn (mut c TcpConn) set_read_deadline(deadline time.Time) {
}

pub fn (mut c TcpConn) write_deadline() !time.Time {
if c.write_deadline.unix == 0 {
if c.write_deadline.unix_time() == 0 {
return c.write_deadline
}
return error('none')
Expand Down Expand Up @@ -450,7 +450,7 @@ pub fn (mut l TcpListener) accept_only() !&TcpConn {
}

pub fn (c &TcpListener) accept_deadline() !time.Time {
if c.accept_deadline.unix != 0 {
if c.accept_deadline.unix_time() != 0 {
return c.accept_deadline
}
return error('invalid deadline')
Expand Down
4 changes: 2 additions & 2 deletions vlib/net/udp.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn (mut c UdpConn) read(mut buf []u8) !(int, Addr) {
}

pub fn (c &UdpConn) read_deadline() !time.Time {
if c.read_deadline.unix == 0 {
if c.read_deadline.unix_time() == 0 {
return c.read_deadline
}
return error('none')
Expand All @@ -133,7 +133,7 @@ pub fn (mut c UdpConn) set_read_deadline(deadline time.Time) {
}

pub fn (c &UdpConn) write_deadline() !time.Time {
if c.write_deadline.unix == 0 {
if c.write_deadline.unix_time() == 0 {
return c.write_deadline
}
return error('none')
Expand Down
6 changes: 3 additions & 3 deletions vlib/net/unix/stream.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn (mut c StreamConn) read(mut buf []u8) !int {

// read_deadline returns the read deadline
pub fn (mut c StreamConn) read_deadline() !time.Time {
if c.read_deadline.unix == 0 {
if c.read_deadline.unix_time() == 0 {
return c.read_deadline
}
return error('none')
Expand All @@ -165,7 +165,7 @@ pub fn (mut c StreamConn) set_read_deadline(deadline time.Time) {

// write_deadline returns the write deadline
pub fn (mut c StreamConn) write_deadline() !time.Time {
if c.write_deadline.unix == 0 {
if c.write_deadline.unix_time() == 0 {
return c.write_deadline
}
return error('none')
Expand Down Expand Up @@ -296,7 +296,7 @@ pub fn (mut l StreamListener) accept() !&StreamConn {

// accept_deadline returns the deadline until a new client is accepted
pub fn (l &StreamListener) accept_deadline() !time.Time {
if l.accept_deadline.unix != 0 {
if l.accept_deadline.unix_time() != 0 {
return l.accept_deadline
}
return error('no deadline')
Expand Down
2 changes: 1 addition & 1 deletion vlib/net/websocket/websocket_client.v
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn (mut ws Client) listen() ! {
}
.pong {
ws.debug_log('read: pong')
ws.last_pong_ut = time.now().unix
ws.last_pong_ut = time.now().unix_time()
ws.send_message_event(msg)
if msg.payload.len > 0 {
unsafe { msg.free() }
Expand Down
6 changes: 3 additions & 3 deletions vlib/net/websocket/websocket_server.v
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn (mut s Server) handle_ping() {
}
clients_to_remove << c.client.id
}
if (time.now().unix - c.client.last_pong_ut) > s.get_ping_interval() * 2 {
if (time.now().unix_time() - c.client.last_pong_ut) > s.get_ping_interval() * 2 {
clients_to_remove << c.client.id
c.client.close(1000, 'no pong received') or { continue }
}
Expand Down Expand Up @@ -153,7 +153,7 @@ pub fn (mut s Server) handle_handshake(mut conn net.TcpConn, key string) !&Serve
client_state: ClientState{
state: .open
}
last_pong_ut: time.now().unix
last_pong_ut: time.now().unix_time()
id: rand.uuid_v4()
}
mut server_client := &ServerClient{
Expand Down Expand Up @@ -228,7 +228,7 @@ fn (mut s Server) accept_new_client() !&Client {
client_state: ClientState{
state: .open
}
last_pong_ut: time.now().unix
last_pong_ut: time.now().unix_time()
id: rand.uuid_v4()
}
return c
Expand Down
2 changes: 1 addition & 1 deletion vlib/orm/orm_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ fn test_orm() {
}!

assert data.len == 1
assert tnow.unix == data[0].create.unix
assert tnow.unix_time() == data[0].create.unix_time()

mod := Module{}

Expand Down
4 changes: 2 additions & 2 deletions vlib/os/environment_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ fn test_environ() {
}

fn test_setenv_var_not_exists() {
key := time.new_time(time.now()).unix
key := time.new_time(time.now()).unix_time()
os.setenv('foo${key}', 'bar', false)
assert os.getenv('foo${key}') == 'bar'
}

fn test_getenv_empty_var() {
key := time.new_time(time.now()).unix
key := time.new_time(time.now()).unix_time()
os.setenv('empty${key}', '""', false)
assert os.getenv('empty${key}') == '""'
}
10 changes: 5 additions & 5 deletions vlib/os/os_stat_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ fn test_stat() {

mut fstat := os.stat(test_file)!
eprintln(@LOCATION)
eprintln(' | start_time: ${start_time.unix}\n | end_time: ${end_time.unix}\n | fstat.ctime: ${fstat.ctime}\n | fstat.mtime: ${fstat.mtime}')
eprintln(' | start_time: ${start_time.unix_time()}\n | end_time: ${end_time.unix_time()}\n | fstat.ctime: ${fstat.ctime}\n | fstat.mtime: ${fstat.mtime}')
assert fstat.get_filetype() == .regular
assert fstat.size == u64(test_content.len)
assert fstat.ctime >= start_time.unix
assert fstat.ctime <= end_time.unix
assert fstat.mtime >= start_time.unix
assert fstat.mtime <= end_time.unix
assert fstat.ctime >= start_time.unix_time()
assert fstat.ctime <= end_time.unix_time()
assert fstat.mtime >= start_time.unix_time()
assert fstat.mtime <= end_time.unix_time()

$if !windows {
os.chmod(test_file, 0o600)!
Expand Down
2 changes: 1 addition & 1 deletion vlib/time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import time
s := '2018-01-27 12:48:34'
t := time.parse(s) or { panic('failing format: ${s} | err: ${err}') }
println(t)
println(t.unix_unix())
println(t.unix_time())
```

V's time module also has these parse methods:
Expand Down
2 changes: 1 addition & 1 deletion vlib/time/misc/misc.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module misc
import rand
import time

const start_time_unix = time.now().unix
const start_time_unix = time.now().unix_time()

// random returns a random time struct in *the past*.
pub fn random() time.Time {
Expand Down
12 changes: 6 additions & 6 deletions vlib/time/misc/misc_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fn test_random() {
t2 := tmisc.random()
t3 := tmisc.random()
t4 := tmisc.random()
assert t1.unix != t2.unix
assert t1.unix != t3.unix
assert t1.unix != t4.unix
assert t2.unix != t3.unix
assert t2.unix != t4.unix
assert t3.unix != t4.unix
assert t1.unix_time() != t2.unix_time()
assert t1.unix_time() != t3.unix_time()
assert t1.unix_time() != t4.unix_time()
assert t2.unix_time() != t3.unix_time()
assert t2.unix_time() != t4.unix_time()
assert t3.unix_time() != t4.unix_time()
}
10 changes: 5 additions & 5 deletions vlib/time/parse_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn test_parse() {
}
assert t.year == 2018 && t.month == 1 && t.day == 27 && t.hour == 12 && t.minute == 48
&& t.second == 34
assert t.unix == 1517057314
assert t.unix_time() == 1517057314
}

fn test_parse_invalid() {
Expand All @@ -33,7 +33,7 @@ fn test_parse_rfc2822() {
}
assert t1.year == 2019 && t1.month == 12 && t1.day == 12 && t1.hour == 6 && t1.minute == 7
&& t1.second == 45
assert t1.unix == 1576130865
assert t1.unix_time() == 1576130865
s2 := 'Thu 12 Dec 2019 06:07:45 +0800'
t2 := time.parse_rfc2822(s2) or {
eprintln('> failing format: ${s2} | err: ${err}')
Expand All @@ -42,7 +42,7 @@ fn test_parse_rfc2822() {
}
assert t2.year == 2019 && t2.month == 12 && t2.day == 12 && t2.hour == 6 && t2.minute == 7
&& t2.second == 45
assert t2.unix == 1576130865
assert t2.unix_time() == 1576130865
}

fn test_parse_rfc2822_invalid() {
Expand Down Expand Up @@ -192,14 +192,14 @@ fn test_ad_second_to_parse_result_in_2001() {
now_tm := time.parse('2001-01-01 04:00:00')!
future_tm := now_tm.add_seconds(60)
assert future_tm.str() == '2001-01-01 04:01:00'
assert now_tm.unix < future_tm.unix
assert now_tm.unix_time() < future_tm.unix_time()
}

fn test_ad_second_to_parse_result_pre_2001() {
now_tm := time.parse('2000-01-01 04:00:00')!
future_tm := now_tm.add_seconds(60)
assert future_tm.str() == '2000-01-01 04:01:00'
assert now_tm.unix < future_tm.unix
assert now_tm.unix_time() < future_tm.unix_time()
}

fn test_parse_format() {
Expand Down
3 changes: 1 addition & 2 deletions vlib/time/time_format_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ const time_to_test = time.Time{
hour: 21
minute: 23
second: 42
unix: 332198622
}

fn test_now_format() {
t := time.now()
u := t.unix
u := t.unix_time()
assert t.format() == time.unix(int(u)).format()
}

Expand Down
4 changes: 2 additions & 2 deletions vlib/vweb/assets/assets.v
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ fn (am AssetManager) get_cache_key(asset_type string) string {
mut latest_modified := i64(0)
for asset in am.get_assets(asset_type) {
files_salt += asset.file_path
if asset.last_modified.unix > latest_modified {
latest_modified = asset.last_modified.unix
if asset.last_modified.unix_time() > latest_modified {
latest_modified = asset.last_modified.unix_time()
}
}
hash := md5.sum(files_salt.bytes()).hex()
Expand Down

0 comments on commit 990a8c2

Please sign in to comment.