-
Notifications
You must be signed in to change notification settings - Fork 67
add localetimezone support #32
Conversation
leodido
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edits to the parser should be made into the .rl file.
Anyway, it's not perfectly clear to me what you are trying to obtain in this case. Is theWithTimezone option what you want? What type of option do you want to implement? Could you please explain it better? Thanks :)
|
In my servers , timezone setting is not utc.
If I use default parse, it will convert to utc time 17:09:42. if I use WithTimezone,it will be converted to other. None of them match the real time. |
|
Which would be the "real time"? Also, your pst, _ := time.LoadLocation("PST")
i := []byte(`<13>Nov 22 17:09:42 xxx kernel: [118479565.921459] EXT4-fs warning (device sda8): ext4_dx_add_entry:2006: Directory index full!`)
p := NewParser(WithLocaleTimezone(pst))
m, _ := p.Parse(i)If you use |
return WithTimezone will convert UTC time "0000-11-22 17:09:42 +0000 UTC" to "0000-11-22 12:13:40 -0456 LMT". |
Signed-off-by: Leonardo Di Donato <[email protected]>
Signed-off-by: Leonardo Di Donato <[email protected]>
Signed-off-by: Leonardo Di Donato <[email protected]>
Signed-off-by: Leonardo Di Donato <[email protected]>
|
Ok @datastream, I updated the Ragel definition, generated the parser from it, updated the docs, and inserted an example for the new Can you please double-check now it's behavior is as intended? Thanks! |
datastream
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update doc
rfc3164/example_test.go
Outdated
| } | ||
|
|
||
| func Example_withlocaletimezone() { | ||
| pst, _ := time.LoadLocation("PST") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use time.LoadLocation("America/New_York") instead. time.LoadLocation("PST") will not work.
rfc3164/example_test.go
Outdated
| // Facility: (*uint8)(1), | ||
| // Severity: (*uint8)(5), | ||
| // Priority: (*uint8)(13), | ||
| // Timestamp: (*time.Time)(0000-11-22 17:09:42 +0000 UTC), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use please use time.LoadLocation("America/New_York"), it will return Timestamp: (*time.Time)(0000-11-22 17:09:42 +0000 LMT)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I obtain 0000-11-22 17:09:42 -0456 LMT not 0000-11-22 17:09:42 +0000 LMT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see in the sent commit
…Timezone option Signed-off-by: Leonardo Di Donato <[email protected]>
|
It looks good to me. |
| } else { | ||
| if m.timezone != nil { | ||
| t, _ = time.ParseInLocation(time.Stamp, string(m.text()), m.timezone) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be open to a refactor here so that the time isn't parsed twice here where the first result ends up being ignored?
I think it can be achieved by always using ParseInLocation but then with UTC if no custom option is given?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, there's no release yet with this functionality included, would it be possible to make a new release as well (maybe even after adding this optimization?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to look at a PR with such optimization @dbussink
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/rfc3164/machine.go.rl b/rfc3164/machine.go.rl
index 4d13817..6629696 100644
--- a/rfc3164/machine.go.rl
+++ b/rfc3164/machine.go.rl
@@ -38,20 +38,37 @@ action set_prival {
}
action set_timestamp {
- if t, e := time.Parse(time.Stamp, string(m.text())); e != nil {
- m.err = fmt.Errorf("%s [col %d]", e, m.p)
- fhold;
- fgoto fail;
- } else {
- if m.timezone != nil {
- t, _ = time.ParseInLocation(time.Stamp, string(m.text()), m.timezone)
- }
- output.timestamp = t.AddDate(m.yyyy, 0, 0)
- if m.loc != nil {
- output.timestamp = output.timestamp.In(m.loc)
- }
- output.timestampSet = true
- }
+ if m.timezone != nil {
+ if t, e := time.ParseInLocation(time.Stamp, string(m.text()), m.timezone); e != nil {
+ m.err = fmt.Errorf("%s [col %d]", e, m.p)
+ (m.p)--
+
+ {
+ goto st373
+ }
+ } else {
+ output.timestamp = t.AddDate(m.yyyy, 0, 0)
+ if m.loc != nil {
+ output.timestamp = output.timestamp.In(m.loc)
+ }
+ output.timestampSet = true
+ }
+ } else {
+ if t, e := time.Parse(time.Stamp, string(m.text())); e != nil {
+ m.err = fmt.Errorf("%s [col %d]", e, m.p)
+ (m.p)--
+
+ {
+ goto st373
+ }
+ } else {
+ output.timestamp = t.AddDate(m.yyyy, 0, 0)
+ if m.loc != nil {
+ output.timestamp = output.timestamp.In(m.loc)
+ }
+ output.timestampSet = true
+ }
+ }
}
action set_rfc3339 {
How about this one?
not all servers' timezone setting is utc.