Skip to content

Commit

Permalink
Extracted the checking for timezone offset
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdsam committed Feb 13, 2017
1 parent be060d2 commit 8d64d2a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ Utils.parseDateTimeField = function(field, options) {
if (SugarDate.isValid(parsedDateWithTimezone)) {
Utils.Logger.debug('Utils.parseDateTimeField: parsedDateWithTimezone:', parsedDateWithTimezone.toISOString());

var hasTZOffset = new RegExp('[zZ]|[+-][01]\d:?[0-5]\d').test(field);
var hasTZOffset = Utils.hasTZOffset(field);

// Convert to string. Important to remove offset/tz info (if none was provided originally)
// or moment will ignore the passed in tz in later step.
Expand All @@ -566,6 +566,21 @@ Utils.parseDateTimeField = function(field, options) {
return rtnObject;
};


/**
* Utils.hasTZOffset - Checks to see if the string has a timezone offset
* Examples
* - `-06:00`
* - `+0600`
* - `Z`
*
* @param {String} str The date string to be checked
* @return {Boolean} true or false
*/
Utils.hasTZOffset = function(str) {
return new RegExp('[zZ]|[+-][01]\d:?[0-5]\d').test(str);
};

/**
* Parses a boolean-ish input into a boolean object.
*
Expand Down

0 comments on commit 8d64d2a

Please sign in to comment.