Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnixTime in node.js #987

Merged
merged 14 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ describe('nodejs', function () {
});
});
});

it('should put and get UnixTime date correctly', function (done) {
var d = new Date('2016-04-13T00:00:00.000Z');
testClient.intModel.putUnixTimeDate(d, function (error, result) {
should.not.exist(error);
testClient.intModel.getUnixTime(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, d);
done();
});
});
});

it('should throw an error for invalid UnixTime date anf get null value for UnixTime', function (done) {
testClient.intModel.getInvalidUnixTime(function (error, result) {
should.exist(error);
testClient.intModel.getNullUnixTime(function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
});

describe('CompositeBoolInt Client', function () {
Expand Down Expand Up @@ -1891,6 +1914,13 @@ describe('nodejs', function () {
});
});

it('should work when path has a paramaeter in UnixTime format', function (done) {
testClient.paths.unixTimeUrl(new Date('2016-04-13T00:00:00.000Z'), function (error, result) {
should.not.exist(error);
done();
});
});

it('should work when path has datetime', function (done) {
testClient.paths.dateTimeValid(new Date('2012-01-01T01:01:01Z'), function (error, result) {
should.not.exist(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getUnixTime(callback: ServiceCallback<number>): void;
getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getUnixTime(callback: ServiceCallback<Date>): void;

/**
* Put datetime encoded as Unix time
*
* @param {number} intBody
* @param {date} intBody
*
* @param {object} [options] Optional Parameters.
*
Expand All @@ -195,8 +195,8 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
putUnixTimeDate(intBody: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: number, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: Date, callback: ServiceCallback<void>): void;

/**
* Get invalid Unix time value
Expand All @@ -209,8 +209,8 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getInvalidUnixTime(callback: ServiceCallback<number>): void;
getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getInvalidUnixTime(callback: ServiceCallback<Date>): void;

/**
* Get null Unix time value
Expand All @@ -223,6 +223,6 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getNullUnixTime(callback: ServiceCallback<number>): void;
getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getNullUnixTime(callback: ServiceCallback<Date>): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ IntModel.prototype.putMin64 = function (intBody, options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1293,7 +1293,7 @@ IntModel.prototype.getUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand All @@ -1313,7 +1313,7 @@ IntModel.prototype.getUnixTime = function (options, callback) {
/**
* Put datetime encoded as Unix time
*
* @param {number} intBody
* @param {date} intBody
*
* @param {object} [options] Optional Parameters.
*
Expand Down Expand Up @@ -1343,9 +1343,10 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
}
// Validate
try {
if (intBody === null || intBody === undefined || typeof intBody !== 'number') {
throw new Error('intBody cannot be null or undefined and it must be of type number.');
}
if(!intBody || !(intBody instanceof Date ||
(typeof intBody.valueOf() === 'string' && !isNaN(Date.parse(intBody))))) {
throw new Error('intBody cannot be null or undefined and it must be of type date.');
}
} catch (error) {
return callback(error);
}
Expand Down Expand Up @@ -1380,7 +1381,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
required: true,
serializedName: 'intBody',
type: {
name: 'Number'
name: 'UnixTime'
}
};
requestModel = client.serialize(requestModelMapper, intBody, 'intBody');
Expand Down Expand Up @@ -1445,7 +1446,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1528,7 +1529,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand Down Expand Up @@ -1559,7 +1560,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1642,7 +1643,7 @@ IntModel.prototype.getNullUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getUnixTime(callback: ServiceCallback<number>): void;
getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getUnixTime(callback: ServiceCallback<Date>): void;

/**
* Put datetime encoded as Unix time
*
* @param {number} intBody
* @param {date} intBody
*
* @param {object} [options] Optional Parameters.
*
Expand All @@ -292,8 +292,8 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
putUnixTimeDate(intBody: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: number, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
putUnixTimeDate(intBody: Date, callback: ServiceCallback<void>): void;

/**
* Get invalid Unix time value
Expand All @@ -306,8 +306,8 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getInvalidUnixTime(callback: ServiceCallback<number>): void;
getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getInvalidUnixTime(callback: ServiceCallback<Date>): void;

/**
* Get null Unix time value
Expand All @@ -320,6 +320,6 @@ export interface IntModel {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<number>): void;
getNullUnixTime(callback: ServiceCallback<number>): void;
getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<Date>): void;
getNullUnixTime(callback: ServiceCallback<Date>): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ IntModel.prototype.putMin64 = function (intBody, options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1293,7 +1293,7 @@ IntModel.prototype.getUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand All @@ -1313,7 +1313,7 @@ IntModel.prototype.getUnixTime = function (options, callback) {
/**
* Put datetime encoded as Unix time
*
* @param {number} intBody
* @param {date} intBody
*
* @param {object} [options] Optional Parameters.
*
Expand Down Expand Up @@ -1343,9 +1343,10 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
}
// Validate
try {
if (intBody === null || intBody === undefined || typeof intBody !== 'number') {
throw new Error('intBody cannot be null or undefined and it must be of type number.');
}
if(!intBody || !(intBody instanceof Date ||
(typeof intBody.valueOf() === 'string' && !isNaN(Date.parse(intBody))))) {
throw new Error('intBody cannot be null or undefined and it must be of type date.');
}
} catch (error) {
return callback(error);
}
Expand Down Expand Up @@ -1380,7 +1381,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
required: true,
serializedName: 'intBody',
type: {
name: 'Number'
name: 'UnixTime'
}
};
requestModel = client.serialize(requestModelMapper, intBody, 'intBody');
Expand Down Expand Up @@ -1445,7 +1446,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1528,7 +1529,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand Down Expand Up @@ -1559,7 +1560,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) {
*
* {Error} err - The Error object if an error occurred, null otherwise.
*
* {number} [result] - The deserialized result object.
* {date} [result] - The deserialized result object.
*
* {object} [request] - The HTTP Request object if an error did not occur.
*
Expand Down Expand Up @@ -1642,7 +1643,7 @@ IntModel.prototype.getNullUnixTime = function (options, callback) {
required: false,
serializedName: 'parsedResponse',
type: {
name: 'Number'
name: 'UnixTime'
}
};
result = client.deserialize(resultMapper, parsedResponse, 'result');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export interface Paths {
/**
* Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
*
* @param {number} unixTimeUrlPath Unix time encoded value
* @param {date} unixTimeUrlPath Unix time encoded value
*
* @param {object} [options] Optional Parameters.
*
Expand All @@ -408,8 +408,8 @@ export interface Paths {
* @param {ServiceCallback} [callback] callback function; see ServiceCallback
* doc in ms-rest index.d.ts for details
*/
unixTimeUrl(unixTimeUrlPath: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
unixTimeUrl(unixTimeUrlPath: number, callback: ServiceCallback<void>): void;
unixTimeUrl(unixTimeUrlPath: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<void>): void;
unixTimeUrl(unixTimeUrlPath: Date, callback: ServiceCallback<void>): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,7 @@ Paths.prototype.arrayCsvInPath = function (arrayPath, options, callback) {
/**
* Get the date 2016-04-13 encoded value as '1460505600' (Unix time)
*
* @param {number} unixTimeUrlPath Unix time encoded value
* @param {date} unixTimeUrlPath Unix time encoded value
*
* @param {object} [options] Optional Parameters.
*
Expand Down Expand Up @@ -2491,17 +2491,18 @@ Paths.prototype.unixTimeUrl = function (unixTimeUrlPath, options, callback) {
}
// Validate
try {
if (unixTimeUrlPath === null || unixTimeUrlPath === undefined || typeof unixTimeUrlPath !== 'number') {
throw new Error('unixTimeUrlPath cannot be null or undefined and it must be of type number.');
}
if(!unixTimeUrlPath || !(unixTimeUrlPath instanceof Date ||
(typeof unixTimeUrlPath.valueOf() === 'string' && !isNaN(Date.parse(unixTimeUrlPath))))) {
throw new Error('unixTimeUrlPath cannot be null or undefined and it must be of type date.');
}
} catch (error) {
return callback(error);
}

// Construct URL
var requestUrl = this.client.baseUri +
'//paths/int/1460505600/{unixTimeUrlPath}';
requestUrl = requestUrl.replace('{unixTimeUrlPath}', encodeURIComponent(unixTimeUrlPath.toString()));
requestUrl = requestUrl.replace('{unixTimeUrlPath}', encodeURIComponent(client.serialize({required: true, serializedName: 'unixTimeUrlPath', type: {name: 'UnixTime'}}, unixTimeUrlPath, 'unixTimeUrlPath')));
// trim all duplicate forward slashes in the url
var regex = /([^:]\/)\/+/gi;
requestUrl = requestUrl.replace(regex, '$1');
Expand Down
Loading