Skip to content

Commit 70358e0

Browse files
committed
Added AV.Cloud.getServerDate()
1 parent b03fff4 commit 70358e0

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/cloudfunction.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ module.exports = function(AV) {
3434
})._thenRunCallbacks(options);
3535
},
3636

37+
/**
38+
* Make a call to request server date time.
39+
* @param {Object} options A Backbone-style options object
40+
* options.success, if set, should be a function to handle a successful
41+
* call to a cloud function. options.error should be a function that
42+
* handles an error running the cloud function. Both functions are
43+
* optional. Both functions take a single argument.
44+
* @return {AV.Promise} A promise that will be resolved with the result
45+
* of the function.
46+
* @since 0.5.9
47+
*/
48+
getServerDate: function(options) {
49+
var request = AV._request("date", null, null, 'GET');
50+
51+
return request.then(function(resp) {
52+
return AV._decode(null, resp);
53+
})._thenRunCallbacks(options);
54+
},
55+
3756
/**
3857
* Makes a call to request a sms code for operation verification.
3958
* @param {Object} data The mobile phone number string or a JSON

lib/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ module.exports = function(AV) {
354354
if (route !== "batch" &&
355355
route !== "classes" &&
356356
route !== "files" &&
357+
route !== "date" &&
357358
route !== "functions" &&
358359
route !== "login" &&
359360
route !== "push" &&

test/cloud.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe("AV.Cloud", function() {
2+
describe("#getServerDate", function(){
3+
this.timeout(10000);
4+
it("should return a date.", function(done){
5+
AV.Cloud.getServerDate().then(function(date) {
6+
expect(date).to.be.a('object');
7+
expect(date instanceof Date).to.be(true);
8+
done();
9+
}).catch(function(err) {
10+
throw err;
11+
});
12+
});
13+
});
14+
});

0 commit comments

Comments
 (0)