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

Timestamp type inconsistency #7

Open
mpickering opened this issue Dec 19, 2014 · 15 comments
Open

Timestamp type inconsistency #7

mpickering opened this issue Dec 19, 2014 · 15 comments

Comments

@mpickering
Copy link

In the documentation for the file object a timestamp is given as an integer

"timestamp" : 1356032811,

but in many other places, different timestamps are given as strings. For example in the specification of message.

"ts": "1355517523.000005"

Should these two values be treated the same or do they have different meanings?

@ernesto-jimenez
Copy link

I believe ts is a per-channel unique timestamp and it's used to identify message events. see https://api.slack.com/events/message

@mpickering
Copy link
Author

Do you know what the digits after the decimal point indicate? Are they just to ensure uniqueness?

@paulhammond
Copy link
Contributor

Thanks for asking about this! In general there are two different things called "timestamps" in our API:

The first are properties that are unix timestamps, usually indicating when something was created or updated, usually called "created" or "edited". These should all be integers (although it's possible, despite checking several times recently, that we've missed one).

The second are the message timestamps, which always use the "ts" name (eg: "ts", "event_ts"). These are returned as strings. Even though they look like floats, they should always be stored and compared as strings - because floats occasionally lose precision and that would be bad here.

The bit after the decimal point is a sequence that guarantees uniqueness and ordering:

  • A message in a channel will have a unique TS for that channel (two messages in two different channels can have the same TS).
  • If message A is posted before message B then A's TS will be less than B's.

Knowing all that, it becomes clear that the "timestamp" property on files is badly named. We've just introduced a new "created" property that better describes what it is, which will be returned by our APIs from today onwards. We'll maintain backwards compatibility by supporting the old "timestamp" property too.

I'm going to leave this issue open, because I'd like to get all of this documented in our docs, and not just on a github issue.

@mpickering
Copy link
Author

Thank you for the detailed reply. I just noticed on the response to rtm.start that in team the limit_ts has a format which corresponds to neither of these schemes. Is this a bug? I infact decided to store these type stamps as a pair of integers (seconds since epoch and unique identifier) so this caused the parse to fail.

"limit_ts":"1414771324000055"

@paulhammond
Copy link
Contributor

That is a bug. I'm talking to the team about it now!

@paulhammond
Copy link
Contributor

And it's fixed, by removing that property entirely - it only appeared for some teams, but shouldn't have been there at all. Thanks for pointing it out!

@davclark
Copy link

davclark commented Mar 6, 2015

To clarify the above, if a timestamp from one group (before the decimal) is smaller than the timestamp from another - can I assume that means it came before? Even better, can I reliably map these to (approximate) real-world times?

[edit: given recent activity, I'd like to point out that @paulhammond says the timestamps are unix (i.e., posix) times above.]

@lchase
Copy link

lchase commented May 11, 2015

When was this fixed? Did it only apply to certain APIs? I am querying groups.history and the response doesn't include a created for the returned messages, still just ts.

@Fabszn
Copy link

Fabszn commented Sep 14, 2015

Hello,
Is it planned to add onto event type :message, new property 'created' with the date and time when the message has been created ?

Regards

@ichthyos
Copy link

ichthyos commented Mar 19, 2017

Paul's reply above was very helpful -- thanks very much.

Just wanted to note that the documentation for the oldest and latest args to channels.history might need to be updated to specify integers rather than floats.

I have filed feedback with Slack on a related issue for the behavior of the channels.history method, and will follow up to request the docs be updated if those args are supposed to be integers.

@ken9ross
Copy link

ken9ross commented Dec 7, 2017

Do I understand correctly that to uniquely identify a message we need:
team(aka workspace)_id.channel_id.message_ts?

Is it anticipated that adding Enterprise Grid will add an additional prefix to that or will team_id remain globally unique?

@Galvin-wjw
Copy link

If I use Webhook to send msgs to a channel, how can I get the message timestamp?
And I am not the admin of the workspace , Can I delete the Webhook messages?(I create the webhook plugin)

@namedgraph
Copy link

@paulhammond so where is that created property? I don't see it anywhere in the documentation:
https://api.slack.com/messaging/retrieving

I think it's quite unheard of for a serious web API not to provide metadata such as created/modified in the response payload. Not being able to retrieve message timeline makes it pretty much useless.

abustany added a commit to abustany/slack that referenced this issue Apr 8, 2022
This field should always be stored/used as a string according to [1].
This also makes the type more consistent across events.

[1] slackhq/slack-api-docs#7 (comment)
abustany added a commit to abustany/slack that referenced this issue Apr 11, 2022
This field should always be stored/used as a string according to [1].
This also makes the type more consistent across events.

[1] slackhq/slack-api-docs#7 (comment)
@JobinBiju
Copy link

JobinBiju commented Oct 29, 2022

The timestamp in file upload is still inconsistent. Now it is returning an integer timestamp. Expected is a float in string format. I need to pass this timestamp to reactions.add api. Please tell a workaround or fix this.

@starball5
Copy link

Related on Stack Overflow: What is the meaning of the parts of a Slack API timestamp when it has a dot in it? (I wrote up some of the info here as a Q&A pair since someone posted a non-answer in another question asking about it).

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

No branches or pull requests