Skip to content

Fix session endpoint - #584

Merged
vkuznecovas merged 2 commits into
masterfrom
fix-session-endpoint
Nov 29, 2018
Merged

Fix session endpoint#584
vkuznecovas merged 2 commits into
masterfrom
fix-session-endpoint

Conversation

@vkuznecovas

Copy link
Copy Markdown
Contributor

Closes #583

Found this while refactoring the session storage.

Comment thread tequilapi/endpoints/sessions_test.go Outdated
Comment thread tequilapi/endpoints/sessions_test.go Outdated
Comment thread tequilapi/endpoints/sessions_test.go Outdated
soffokl
soffokl previously approved these changes Nov 28, 2018
Comment thread tequilapi/endpoints/sessions.go Outdated
ServiceType: se.ServiceType,
ProviderCountry: se.ProviderCountry,
DateStarted: se.Started.Format("2018-10-29 16:22:05"),
DateStarted: se.Started.Format("2006-01-02 15:04:05"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked okey from the first sight. And then I started thinking (maybe this is the real problem 😄 )
What timezone this format uses? What timezone we use when we set actual session start time?
Maybe its better to use one of predefined ISO formats with UTC time zone? In that case session times will be comparable in whole world.
These are not change requests but more like answers we need to answer and to do that maybe we have to look deeper. This looks like good opportunity to do that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the format to RFC3339 which is basicly a stricter ISO 8601.

@vkuznecovas
vkuznecovas force-pushed the fix-session-endpoint branch 2 times, most recently from fde035a to 459ca08 Compare November 29, 2018 07:47
Comment thread tequilapi/endpoints/sessions.go Outdated
ServiceType: se.ServiceType,
ProviderCountry: se.ProviderCountry,
DateStarted: se.Started.Format("2018-10-29 16:22:05"),
DateStarted: se.Started.UTC().Format(time.RFC3339),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to set time in UTC before persisting session itself, not when rendering in presentation layer. I assume RFC3339 formatting includes timezone too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does - any reason why you don't want the UTC time there?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start time in UTC must be set on session creation - my point is, let's keep times in UTC in database too.

@tadovas tadovas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be alright. Rule of thumb - presentation layer should take care of presentation functionality only

ServiceType: se.ServiceType,
ProviderCountry: se.ProviderCountry,
DateStarted: se.Started.Format("2018-10-29 16:22:05"),
DateStarted: se.Started.Format(time.RFC3339),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use with timezone specifying explicit TZ as: 2006-01-02 15:04:05-0700
Question is, will other peer know how to interpret this, how this agreement on format is passed?
I ALWAYS use unix timestamp in UTC zone. Peer will parse representation for itself as it wishes.
Bonus for this, you can stuff unix timestamp into long type and operate with time arithmetics more easily.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll be able to parse the RFC3339 in any language easily. It does provide timezone information. One thing that unix timestamp is lacking is the human readability. RFC3339 is both human comprehendible and machine readable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say its a good time to introduce UTC unix timestamp, since we are changing format anyways. Will reduce complexity for users later on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zolia golden rule with time - never ever do direct arithmetics with times. https://en.wikipedia.org/wiki/Leap_second

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the RFC3339 is still the way to go. You said it youself - peer will have to parse the timestamp to make sense of it. Why have that step as extra? If you're parsing anyway, you'll be able to parse RFC3339 with the same ease as a timestamp.

IETF seems to recommend RFC3339 as well:
https://tools.ietf.org/html/rfc7493#section-4.3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, theres cons and pros for that. RFC3339 is representative format as common JSON is too. I see a bunch of pitfalls in such usage, but since event IETF recommends that.. well :)

@vkuznecovas
vkuznecovas merged commit 86bf72a into master Nov 29, 2018
@vkuznecovas
vkuznecovas deleted the fix-session-endpoint branch November 29, 2018 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants