Created
April 27, 2012 22:55
-
-
Save mikebannister/2514079 to your computer and use it in GitHub Desktop.
Time seems to be off on meteor.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>Time Test</title> | |
</head> | |
<body> | |
{{> time_test}} | |
</body> | |
<template name="time_test"> | |
<h1>Time Test</h1> | |
<em>Updates every 3 seconds</em> | |
<p>Server time: {{serverTime}}</p> | |
<p>Client time: {{clientTime}}</p> | |
<p><strong>I think this proves that the time is off on Meteor's server, no¿</strong></p> | |
<p>See source: <a href="https://gist.github.com/2514079">https://gist.github.com/2514079</a></p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.is_client) { | |
Template.time_test.serverTime = function () { | |
return new Date(Session.get('serverTime')).toString(); | |
}; | |
Template.time_test.clientTime = function () { | |
return new Date; | |
}; | |
var updateServerTime = function() { | |
Meteor.call('serverTime', function(err, time) { | |
if (!err) Session.set('serverTime', time); | |
}); | |
}; | |
updateServerTime(); | |
Meteor.setInterval(updateServerTime, 3000); | |
} | |
if (Meteor.is_server) { | |
Meteor.methods({ | |
serverTime: function() { | |
return (new Date).toString(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment