github.com/nuvolaris/goja@v0.0.0-20230825100449-967811910c6d/date_parser_test.go (about)

     1  package goja
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestParseDate(t *testing.T) {
     9  
    10  	tst := func(layout, value string, expectedTs int64) func(t *testing.T) {
    11  		return func(t *testing.T) {
    12  			t.Parallel()
    13  			tm, err := parseDate(layout, value, time.UTC)
    14  			if err != nil {
    15  				t.Fatal(err)
    16  			}
    17  			if tm.Unix() != expectedTs {
    18  				t.Fatal(tm)
    19  			}
    20  		}
    21  	}
    22  
    23  	t.Run("1", tst("2006-01-02T15:04:05.000Z070000", "2006-01-02T15:04:05.000+07:00:00", 1136189045))
    24  	t.Run("2", tst("2006-01-02T15:04:05.000Z07:00:00", "2006-01-02T15:04:05.000+07:00:00", 1136189045))
    25  	t.Run("3", tst("2006-01-02T15:04:05.000Z07:00", "2006-01-02T15:04:05.000+07:00", 1136189045))
    26  	t.Run("4", tst("2006-01-02T15:04:05.000Z070000", "2006-01-02T15:04:05.000+070000", 1136189045))
    27  	t.Run("5", tst("2006-01-02T15:04:05.000Z070000", "2006-01-02T15:04:05.000Z", 1136214245))
    28  	t.Run("6", tst("2006-01-02T15:04:05.000Z0700", "2006-01-02T15:04:05.000Z", 1136214245))
    29  	t.Run("7", tst("2006-01-02T15:04:05.000Z07", "2006-01-02T15:04:05.000Z", 1136214245))
    30  
    31  }