Skip to content

Commit 1363cc8

Browse files
authored
time: update unix time acces, fix issues related to deviating unix times (#21293)
1 parent 9d117fc commit 1363cc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+251
-193
lines changed

.github/workflows/macos_ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
.github/workflows/retry.sh git clone --depth 1 https://github.com/vlang/ved
8383
cd ved && ../v -o ved .
8484
../v -autofree .
85-
../v -prod .
85+
# ../v -prod . # NOTE: temporary disabled due to deprecations. Enable after resolving github.com/vlang/ved/pull/181
8686
cd ..
8787
- name: Build V UI examples
8888
run: |

.github/workflows/v_apps_and_modules_compile_ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
.github/workflows/retry.sh git clone --depth 1 https://github.com/vlang/ved
7575
cd ved && ../v -o ved .
7676
../v -autofree .
77-
../v -prod .
77+
# ../v -prod . # NOTE: temporary disabled due to deprecations. Enable after resolving github.com/vlang/ved/pull/181
7878
cd ..
7979
8080
- name: Build vlang/pdf
@@ -124,8 +124,8 @@ jobs:
124124
v install
125125
echo "Build v-analyzer debug"
126126
v build.vsh debug
127-
echo "Build v-analyzer release"
128-
v build.vsh release
127+
# echo "Build v-analyzer release"
128+
# v build.vsh release # NOTE: temporary disabled due to deprecations.
129129
130130
- name: Format vlang/v-analyzer
131131
run: |

doc/docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ fn main() {
15901590
month: 12
15911591
day: 25
15921592
}
1593-
println(time.new_time(my_time).utc_string())
1593+
println(time.new(my_time).utc_string())
15941594
println('Century: ${my_time.century()}')
15951595
}
15961596
```

examples/2048/2048.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ fn (mut app App) handle_swipe() {
733733
adx, ady := math.abs(dx), math.abs(dy)
734734
dmin := if math.min(adx, ady) > 0 { math.min(adx, ady) } else { 1 }
735735
dmax := if math.max(adx, ady) > 0 { math.max(adx, ady) } else { 1 }
736-
tdiff := int(e.time.unix_time_milli() - s.time.unix_time_milli())
736+
tdiff := int(e.time.unix_milli() - s.time.unix_milli())
737737
// TODO: make this calculation more accurate (don't use arbitrary numbers)
738738
min_swipe_distance := int(math.sqrt(math.min(w, h) * tdiff / 100)) + 20
739739
if dmax < min_swipe_distance {

vlib/context/onecontext/onecontext.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ pub fn (octx OneContext) deadline() ?time.Time {
4343

4444
for ctx in octx.ctxs {
4545
if deadline := ctx.deadline() {
46-
if min.unix_time() == 0 || deadline < min {
46+
if min.unix() == 0 || deadline < min {
4747
min = deadline
4848
}
4949
}
5050
}
5151

52-
if min.unix_time() == 0 {
52+
if min.unix() == 0 {
5353
return none
5454
}
5555

vlib/context/onecontext/onecontext_test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn test_merge_deadline_context_1() {
9595
mut ctx, _ := merge(ctx1, ctx2)
9696

9797
if deadline := ctx.deadline() {
98-
assert deadline.unix_time() != 0
98+
assert deadline.unix() != 0
9999
} else {
100100
assert false
101101
}
@@ -111,7 +111,7 @@ fn test_merge_deadline_context_2() {
111111
mut ctx, _ := merge(ctx1, ctx2)
112112

113113
if deadline := ctx.deadline() {
114-
assert deadline.unix_time() != 0
114+
assert deadline.unix() != 0
115115
} else {
116116
assert false
117117
}

vlib/db/mysql/orm.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn stmt_bind_primitive(mut stmt Stmt, data orm.Primitive) {
244244
stmt.bind_text(data)
245245
}
246246
time.Time {
247-
unix := int(data.unix)
247+
unix := int(data.unix())
248248
stmt_bind_primitive(mut stmt, unix)
249249
}
250250
orm.InfixType {

vlib/db/sqlite/orm.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn bind(stmt Stmt, c &int, data orm.Primitive) int {
140140
err = stmt.bind_text(c, data)
141141
}
142142
time.Time {
143-
err = stmt.bind_int(c, int(data.unix))
143+
err = stmt.bind_int(c, int(data.unix()))
144144
}
145145
orm.InfixType {
146146
err = bind(stmt, c, data.right)

vlib/json/json_test.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn test_encode_decode_sumtype() {
9595
enc := json.encode(game)
9696
// eprintln('Encoded Game: $enc')
9797

98-
assert enc == '{"title":"Super Mega Game","player":{"name":"Monke","_type":"Human"},"other":[{"tag":"Pen","_type":"Item"},{"tag":"Cookie","_type":"Item"},"cat","Stool",{"_type":"Time","value":${t.unix_time()}}]}'
98+
assert enc == '{"title":"Super Mega Game","player":{"name":"Monke","_type":"Human"},"other":[{"tag":"Pen","_type":"Item"},{"tag":"Cookie","_type":"Item"},"cat","Stool",{"_type":"Time","value":${t.unix()}}]}'
9999

100100
dec := json.decode(SomeGame, enc)!
101101
// eprintln('Decoded Game: $dec')
@@ -104,7 +104,7 @@ fn test_encode_decode_sumtype() {
104104
assert game.player == dec.player
105105
assert (game.other[2] as Animal) == .cat
106106
assert dec.other[2] == Entity('cat')
107-
assert (game.other[4] as time.Time).unix_time() == (dec.other[4] as time.Time).unix_time()
107+
assert (game.other[4] as time.Time).unix() == (dec.other[4] as time.Time).unix()
108108
}
109109

110110
fn bar[T](payload string) !Bar { // ?T doesn't work currently
@@ -156,7 +156,7 @@ fn test_parse_user() {
156156
fn test_encode_decode_time() {
157157
user := User2{
158158
age: 25
159-
reg_date: time.new_time(year: 2020, month: 12, day: 22, hour: 7, minute: 23)
159+
reg_date: time.new(year: 2020, month: 12, day: 22, hour: 7, minute: 23)
160160
}
161161
s := json.encode(user)
162162
// println(s)

vlib/net/common.c.v

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import time
44

55
// no_deadline should be given to functions when no deadline is wanted (i.e. all functions
66
// return instantly)
7-
const no_deadline = time.Time{
8-
unix: 0
9-
}
7+
const no_deadline = time.unix(0)
108

119
// no_timeout should be given to functions when no timeout is wanted (i.e. all functions
1210
// return instantly)
@@ -148,7 +146,7 @@ fn @select(handle int, test Select, timeout time.Duration) !bool {
148146
@[inline]
149147
fn select_deadline(handle int, test Select, deadline time.Time) !bool {
150148
// if we have a 0 deadline here then the timeout that was passed was infinite...
151-
infinite := deadline.unix_time() == 0
149+
infinite := deadline.unix() == 0
152150
for infinite || time.now() <= deadline {
153151
timeout := if infinite { net.infinite_timeout } else { deadline - time.now() }
154152
ready := @select(handle, test, timeout) or {

0 commit comments

Comments
 (0)