question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firebase.ServerValue.TIMESTAMP returns object literal (JSON) instead of number

See original GitHub issue

The global variable Firebase.ServerValue.TIMESTAMP returns an object literal ({.sv: "timestamp"}) that make both arithmetic and logical operation not possible to work.

Logical: https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L214

if (notification.notificationType !== 'suspension' || notification.data.suspendedUntil < Firebase.ServerValue.TIMESTAMP) {

notification.data.suspendedUntil < Firebase.ServerValue.TIMESTAMP will always be false. (Note: notification.data.suspendedUntil will return as a string, see next error below).

Arithmetic: https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L457

suspendedUntil = Firebase.ServerValue.TIMESTAMP + 1000*timeLengthSeconds;

Let’s say timeLengthSeconds is 10, the result of suspendedUntil will be "[object Object]10000". Screenshot from my Firebase Forge: screen shot 2013-08-01 at 4 56 55 pm

I haven’t checked for these line codes below, but they seem work fine: https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L295 https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L391 https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L406 https://github.com/firebase/firechat/blob/master/src/js/firechat.js#L441

Thanks.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Tekrajscommented, Sep 11, 2017

Can’t we get the timestamp value directly like in android instead of getting { ‘.sv’: ‘timestamp’ }. Or can we parse it someway to get value? I am also stuck on this.

1reaction
robertdimarcocommented, Aug 16, 2013

@oburakevych When you pass around Firebase.ServerValue.TIMESTAMP, the { '.sv': 'timestamp' } value is used as a placeholder until actually written to Firebase via .set(), .push(), etc.

When one of those methods is called with the TIMESTAMP in it, the client will immediately fire any local events for listeners on that data using the client’s local timestamp offset by the difference between client and server time as determined when you first connected to Firebase. This value is approximate, and becomes updated when the actual server-side write in Firebase completes.

To get the actual server time from Firebase for a write of some kind, you would first write to Firebase (i.e. ref.child('updated_at').set(Firebase.ServerValue.TIMESTAMP); and have listeners for that data (ref.on('value', function(snapshot) { // snapshot.val().updated_at });). There is no way to get the server time synchronously from Firebase, but the local time + server offset time (provided immediately whenever you write to Firebase using the ServerValue) is a good approximation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

firebase.database.ServerValue.TIMESTAMP return an Object
This snippet from the Firebase documentation shows how to set a timestamp: var userLastOnlineRef = firebase.database().ref("users/joe/lastOnline"); ...
Read more >
Timestamp | Firebase - Google
It is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second table is needed...
Read more >
firebase - Go Packages
Use this value to represent a Firebase server timestamp in a data structure. This should be used when you're sending data to Firebase,...
Read more >
firebase - UNPKG
authHeaders = {};\n // Set the headers using Object Literal notation to avoid minification\n this. ... n */\n static now(): Timestamp {\n return...
Read more >
How to Build a Serverless Blog on CodePen
Firebase has a number of features, functions is only one of them. ... The route /posts/aaa should return an empty JSON object, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found