Skip to content

Instantly share code, notes, and snippets.

@mikebannister
Created April 27, 2012 22:55
Show Gist options
  • Save mikebannister/2514079 to your computer and use it in GitHub Desktop.
Save mikebannister/2514079 to your computer and use it in GitHub Desktop.
Time seems to be off on meteor.com
<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>
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