Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Fixed TimeStamp resolution #4

Merged
merged 1 commit into from Dec 25, 2018
Merged

Conversation

PaulAnnekov
Copy link
Contributor

According to the API, timestamps should be in milliseconds: int, <required> milliseconds since the UNIX epoch, used to sequence messages. (must be within previous 30 days). Currently they are in seconds, which breaks messages sequence at least in Transcripts.

@@ -5,8 +5,8 @@ import "testing"
func TestTimeStamp(t *testing.T) {
t.Run("default", func(t *testing.T) {
result := TimeStamp()
if result <= 0 {
t.Errorf("Expected non-zero timestamp, got %v", result)
if result < 10000000000 {
Copy link
Owner

Choose a reason for hiding this comment

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

Just to understand why you changed this: couldn't this still be <= 0 as all that it checks if the value is non-zero and the returned resolution does not really matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to make a basic check if resolution is in milliseconds. If >=1e10 is returned, than it's definitely milliseconds (1970 year), because if it's in seconds - it's 2286 year. I don't think anybody will use this library in 2286.
Yep, it's kind of a magic number. But there is no better way to check for resolution. Also, you can remove it, if you want, because I don't think anybody will break this simple function :).

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I think that makes sense. Let's keep it like this.

@m90
Copy link
Owner

m90 commented Dec 25, 2018

Thanks for the PR, that does indeed look like a bug. It's strange that Chatbase never complained, but well.

Travis should be failing as it is lacking the secrets needed to build on your branch, but I will checkout your branch locally and run the tests here just to be sure.

@m90
Copy link
Owner

m90 commented Dec 25, 2018

Yeah, integration tests pass just fine when the correct environment variable is set.

Copy link
Owner

@m90 m90 left a comment

Choose a reason for hiding this comment

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

💯

@m90 m90 merged commit a075777 into m90:master Dec 25, 2018
@m90
Copy link
Owner

m90 commented Dec 25, 2018

I merged and tagged this as v1.1.1. Thanks for your contribution 🎉

@m90
Copy link
Owner

m90 commented Dec 25, 2018

Whoops, I just noticed that returning int64 instead of int is a breaking API change, i.e. code that updated the library to 1.1.1 will stop compiling. Do you think we should revert this to return ints (which should be the same on 64 bit systems anyways) or do we need to make this v2.0.0 @PaulAnnekov ?

@m90
Copy link
Owner

m90 commented Dec 25, 2018

Actually I think the right thing to do would be to do the following:

  • reverting the type change and keeping the fix so the library sticks to semver
  • changing the types to be int64 and release this as v2.0.0

@m90
Copy link
Owner

m90 commented Dec 25, 2018

I rolled back the type changes and only left the timestamp resolution fix in v1.1.2.

@PaulAnnekov
Copy link
Contributor Author

Yes, it's a breaking change and it doesn't matter int takes 64 bit on 64 bit systems, because if somebody used SetTimeStamp() method - his code will break on next compilation with v1.1.1 on any system.

I think this library is not very popular and nobody used SetTimeStamp() methods, so this change won't affect anybody. But if you want to stick with semver, you should do as you proposed.

@m90
Copy link
Owner

m90 commented Dec 25, 2018

because if somebody used SetTimeStamp() method - his code will break on next compilation with v1.1.1 on any system

It will start behaving as expected (which will be unexpected, but well...), but it won't stop compiling when using v1.1.2 (which ideally should happen when not doing a major version bump).

I think this library is not very popular and nobody used SetTimeStamp() methods, so this change won't affect anybody.

Well I for one use it and it broke my build :) so that alone is definitely worth sticking to semver.

@m90
Copy link
Owner

m90 commented Dec 25, 2018

So v2.0.0 now has int64 timestamps and is at the state of this PR: v2.0.0...5c8c750

Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants