Skip to content

Commit

Permalink
explicitely specify methods and export them
Browse files Browse the repository at this point in the history
  • Loading branch information
devdazed committed Apr 24, 2014
1 parent e02d0b1 commit cd884b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Various Utilities for dealing with Time in Go



## ParseDate(dt interface{}) (time.Time, error)
## ParseDateString(dt string) (t time.Time, err error)

Parses a date from either a `string` or an `int64` into a `time.Time` object.
Parses a date from either a `string` into a `time.Time` object.

## ParseMillis(dt int64) (t time.Time, err error)
Parses a milliseconds-since-epoch time stamp to a time.Time


# License
Expand Down
21 changes: 4 additions & 17 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "time"
import "fmt"

// Takes a string and passes it through Approxidate
// If the date is correct then
func parseDateStr(dt string) (t time.Time, err error) {
// Parses into a time.Time
func ParseDateString(dt string) (t time.Time, err error) {
date := C.struct_timeval{}

ok := C.approxidate(C.CString(dt), &date)
Expand All @@ -21,21 +21,8 @@ func parseDateStr(dt string) (t time.Time, err error) {
return
}

func parseDateInt(dt int64) (t time.Time, err error) {
// Parses a milliseconds-since-epoch time stamp to a time.Time
func ParseMillis(dt int64) (t time.Time, err error) {
t = time.Unix(0, dt*1000*1000)
return
}

func ParseDate(dt interface{}) (time.Time, error) {
idt, ok := dt.(int64)
if ok {
return parseDateInt(idt)
}

sdt, ok := dt.(string)
if ok {
return parseDateStr(sdt)
}

panic("Invlid type supplied for ParseDate")
}

0 comments on commit cd884b3

Please sign in to comment.