forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_utc_timestamp.go
More file actions
40 lines (32 loc) · 816 Bytes
/
fix_utc_timestamp.go
File metadata and controls
40 lines (32 loc) · 816 Bytes
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
package quickfix
import (
"time"
)
//FIXUTCTimestamp is a FIX UTC Timestamp value, implements FieldValue
type FIXUTCTimestamp struct {
Value time.Time
NoMillis bool
}
const (
utcTimestampFormat = "20060102-15:04:05.000"
utcTimestampNoMillisFormat = "20060102-15:04:05"
)
func (f *FIXUTCTimestamp) Read(bytes []byte) error {
var err error
//with millisecs
if f.Value, err = time.Parse(utcTimestampFormat, string(bytes)); err == nil {
return nil
}
//w/o millisecs
if f.Value, err = time.Parse(utcTimestampNoMillisFormat, string(bytes)); err != nil {
return err
}
f.NoMillis = true
return nil
}
func (f FIXUTCTimestamp) Write() []byte {
if f.NoMillis {
return []byte(f.Value.UTC().Format(utcTimestampNoMillisFormat))
}
return []byte(f.Value.UTC().Format(utcTimestampFormat))
}