mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
v.gen.js: fix method calls and other codegen parts, rand module compiles (#11205)
This commit is contained in:
parent
c51f83efba
commit
0121c8b4fd
9 changed files with 301 additions and 130 deletions
24
vlib/time/parse.js.v
Normal file
24
vlib/time/parse.js.v
Normal file
|
@ -0,0 +1,24 @@
|
|||
module time
|
||||
|
||||
// parse returns time from a date string.
|
||||
//
|
||||
// TODO(playX): JS Date expects iso8061 format of strings and other formats
|
||||
// are implementation dependant, we probably want to implement parsing in JS.
|
||||
pub fn parse(s string) Time {
|
||||
mut res := Time{}
|
||||
#let date = new Date(s.str)
|
||||
#res.year.val = date.getFullYear()
|
||||
#res.month.val = date.getMonth()
|
||||
#res.day.val = date.getDay()
|
||||
#res.hour.val = date.getHours()
|
||||
#res.minute.val = date.getMinutes()
|
||||
#res.second.val = date.getSeconds()
|
||||
#res.microsecond.val = date.getMilliseconds() * 1000
|
||||
#res.unix.val = (date.getTime() / 1000).toFixed(0)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn parse_iso8601(s string) ?Time {
|
||||
return parse(s)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue