forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
48 lines (39 loc) · 1.16 KB
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package convert
import (
"strconv"
"time"
)
const (
//ISO8601 is format for ISO8601 dates. Like RFC3339, but without timezone
ISO8601 = "2006-01-02T15:04:05"
)
//ToBool tries to convert string into bool type
func ToBool(value string) (bool, error) {
return strconv.ParseBool(value)
}
//ToInt tries to convert string into int type
func ToInt(value string) (int, error) {
i, err := strconv.ParseInt(value, 10, 64)
return int(i), err
}
//ToUint tries to convert string into int type
func ToUint(value string) (uint, error) {
i, err := strconv.ParseUint(value, 10, 64)
return uint(i), err
}
//ToFloat tries to convert string into float64 type
func ToFloat(value string) (float64, error) {
return strconv.ParseFloat(value, 64)
}
//ToDate tries to convert string into time.Time type
func ToDate(value string) (time.Time, error) {
//is serial format?
serial, err := strconv.ParseFloat(value, 64)
if err == nil {
return time.Unix(int64((serial-25569)*86400), 0), nil
}
return time.Parse(ISO8601, value)
}