Skip to content
Closed
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Setup
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Install chrome
uses: browser-actions/setup-chrome@latest
- name: Install wasmbrowsertest
run: go install github.com/agnivade/wasmbrowsertest@latest
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Test
env:
GOOS: js
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/norunners/vert

go 1.16

require github.com/corbym/gocrest v1.0.5
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/corbym/gocrest v1.0.5 h1:6FUvLjKkKQ2hwMel8OKIZqN3slYEOHIFY9+lVaroFnU=
github.com/corbym/gocrest v1.0.5/go.mod h1:lF3xBPnOU5DYDpa/vUq63SMxUhd5UAwGgmA8Z2pJ/Tk=
8 changes: 7 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vert
import (
"reflect"
"syscall/js"
"time"
)

var (
Expand All @@ -27,7 +28,7 @@ func (v Value) JSValue() js.Value {
// ValueOf returns the Go value as a new value.
func ValueOf(i interface{}) Value {
switch i.(type) {
case nil, js.Value, js.Wrapper:
case nil, js.Value:
return Value{Value: js.ValueOf(i)}
default:
v := reflect.ValueOf(i)
Expand Down Expand Up @@ -90,6 +91,11 @@ func valueOfMap(v reflect.Value) js.Value {

// valueOfStruct returns a new object value.
func valueOfStruct(v reflect.Value) js.Value {
if t, ok := v.Interface().(time.Time); ok {
// special case: Time, instantiates a new js Date object
dateConstructor := js.Global().Get("Date")
return dateConstructor.New(t.Format(time.RFC3339))
}
t := v.Type()
s := object.New()
n := v.NumField()
Expand Down
22 changes: 22 additions & 0 deletions value_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package vert

import (
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"testing"
"time"
)

const isoStringLength = len("yyyy-MM-ddThh:mm:ss")

func TestValueOfTime(t *testing.T) {
now := time.Now()

jsVal := ValueOf(now)

// cut off the timezone information, because second's precision is sufficient for this test
jsValIsoString := jsVal.Call("toISOString").String()
jsValIsoString = jsValIsoString[:isoStringLength]

then.AssertThat(t, jsValIsoString, is.EqualTo(now.UTC().Format(time.RFC3339)[:isoStringLength]))
}