Permalink
Browse files

Adding date utils

  • Loading branch information...
1 parent 9f56b08 commit a12683fff4ef0d111276f93be06d804d3bff2c97 Andre Rodrigues committed Jan 29, 2013
@@ -82,7 +82,7 @@ PushpinService.prototype.createPushpin = function (pushpinData, pushpinImage, ca
entity.PartitionKey = DEFAULT_PARTITION;
if (blob) {
- entity.imageUrl = self.blobClient.getBlobUrl(blob.container, blob.blob).url();
+ entity.imageUrl = self.blobClient.getBlobUrl(blob.container, blob.blob);
}
self.tableClient.insertEntity(TABLE_NAME, entity, callback);
View
@@ -208,6 +208,8 @@ exports.ServiceBusSettings = require('./services/core/servicebussettings');
exports.ServiceManagementSettings = require('./services/core/servicemanagementsettings');
exports.Validate = require('./util/validate');
+exports.date = require('./util/date');
+
/*
* Convenience functions.
*/
@@ -2142,7 +2142,7 @@ BlobService.prototype.listBlobBlocks = function (container, blob, blocklisttype,
* @param {string} [blob] The blob name.
* @param {object} sharedAccessPolicy The shared access policy.
* @param {string} [sharedAccessPolicy.Id] The signed identifier.
-* @param {SharedAccessPermissions} [sharedAccessPolicy.AccessPolicy.Permissions] The permission type.
+* @param {object} [sharedAccessPolicy.AccessPolicy.Permissions] The permission type.
* @param {date|string} [sharedAccessPolicy.AccessPolicy.Start] The time at which the Shared Access Signature becomes valid (The UTC value will be used).
* @param {date|string} sharedAccessPolicy.AccessPolicy.Expiry The time at which the Shared Access Signature becomes expired (The UTC value will be used).
* @return {object} An object with the shared access signature.
@@ -2192,7 +2192,7 @@ BlobService.prototype.generateSharedAccessSignature = function (container, blob,
* @param {string} [blob] The blob name.
* @param {object} [sharedAccessPolicy] The shared access policy.
* @param {string} [sharedAccessPolicy.Id] The signed identifier.
-* @param {SharedAccessPermissions} [sharedAccessPolicy.AccessPolicy.Permissions] The permission type.
+* @param {object} [sharedAccessPolicy.AccessPolicy.Permissions] The permission type.
* @param {date|string} [sharedAccessPolicy.AccessPolicy.Start] The time at which the Shared Access Signature becomes valid (The UTC value will be used).
* @param {date|string} sharedAccessPolicy.AccessPolicy.Expiry The time at which the Shared Access Signature becomes expired (The UTC value will be used).
* @return {object} An object with the blob URL.
View
@@ -0,0 +1,62 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+* Generates a Date object which is in the given days from now.
+*
+* @param {int} days The days timespan.
+* @return {Date}
+*/
+exports.daysFromNow = function (days) {
+ var date = new Date()
+ date.setDate(date.getDate() + days);
+ return date;
+};
+
+/**
+* Generates a Date object which is in the given hours from now.
+*
+* @param {int} hours The hours timespan.
+* @return {Date}
+*/
+exports.hoursFromNow = function (hours) {
+ var date = new Date()
+ date.setHours(date.getHours() + hours);
+ return date;
+};
+
+/**
+* Generates a Date object which is in the given minutes from now.
+*
+* @param {int} minutes The minutes timespan.
+* @return {Date}
+*/
+exports.minutesFromNow = function (minutes) {
+ var date = new Date()
+ date.setMinutes(date.getMinutes() + minutes);
+ return date;
+};
+
+/**
+* Generates a Date object which is in the given seconds from now.
+*
+* @param {int} seconds The seconds timespan.
+* @return {Date}
+*/
+exports.secondsFromNow = function (seconds) {
+ var date = new Date()
+ date.setSeconds(date.getSeconds() + seconds);
+ return date;
+};
@@ -18,6 +18,7 @@ var assert = require('assert');
var fs = require('fs');
var path = require("path");
var util = require('util');
+var sinon = require('sinon');
// Test includes
var testutil = require('../../util/util');
@@ -1277,6 +1278,29 @@ suite('blobservice-tests', function () {
done();
});
+ test('GetBlobSharedUrlWithDuration', function (done) {
+ var containerName = 'container';
+ var blobName = 'blob';
+
+ var blobServiceassert = azure.createBlobService('storageAccount', 'storageAccessKey', 'host.com:80');
+
+ // Mock Date just to ensure a fixed signature
+ this.clock = sinon.useFakeTimers(0, "Date");
+
+ var sharedAccessPolicy = {
+ AccessPolicy: {
+ Expiry: azure.date.minutesFromNow(10);
+ }
+ };
+
+ this.clock.restore();
+
+ var blobUrl = blobServiceassert.getBlobUrl(containerName, blobName, sharedAccessPolicy);
+ assert.equal(blobUrl, 'http://host.com:80/' + containerName + '/' + blobName + '?se=1970-01-01T00%3A10%3A00Z&sr=b&sp=r&sig=LofuDUzdHPpiteauMetANWzDpzd0Vw%2BVMOHyXYCipAM%3D');
+
+ done();
+ });
+
test('responseEmits', function (done) {
var containerName = testutil.generateId(containerNamesPrefix, containerNames, suiteUtil.isMocked);
var blobName = testutil.generateId(blobNamesPrefix, blobNames, suiteUtil.isMocked);
View
@@ -30,6 +30,7 @@ services/table/tableservice-tablequery-tests.js
services/table/tableservice-tests.js
services/sqlAzure/sqlservice-tests.js
util/atomhandler-tests.js
+util/date-tests.js
util/iso8061date-tests.js
util/util-tests.js
util/validate-tests.js
View
@@ -0,0 +1,58 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+var should = require('should');
+var sinon = require('sinon');
+
+var testutil = require('./util');
+var azure = testutil.libRequire('azure');
+
+suite('date-tests', function () {
+ setup(function () {
+ this.clock = sinon.useFakeTimers(0, "Date");
+ });
+
+ teardown(function () {
+ this.clock.restore();
+ });
+
+ test('daysFromNow', function () {
+ var daysInterval = 1;
+ var expectedDate = new Date('Jan 2, 1970 00:00:00 am GMT');
+
+ azure.date.daysFromNow(daysInterval).should.equal(expectedDate);
+ });
+
+ test('hoursFromNow', function () {
+ var hoursInterval = 3;
+ var expectedDate = new Date('Jan 1, 1970 03:00:00 am GMT');
+
+ azure.date.hoursFromNow(hoursInterval).should.equal(expectedDate);
+ });
+
+ test('minutesFromNow', function () {
+ var minutesInterval = 10;
+ var expectedDate = new Date('Jan 1, 1970 00:10:00 am GMT');
+
+ azure.date.minutesFromNow(minutesInterval).should.equal(expectedDate);
+ });
+
+ test('secondsFromNow', function () {
+ var secondsInterval = 20;
+ var expectedDate = new Date('Jan 1, 1970 00:00:20 am GMT');
+
+ azure.date.secondsFromNow(secondsInterval).should.equal(expectedDate);
+ });
+});

0 comments on commit a12683f

Please sign in to comment.