Skip to content

Commit

Permalink
v1.27.0: add validation function tc.parseable()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier Schouten committed Jan 20, 2016
1 parent e301207 commit a61f573
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ The version of the included IANA time zone database is 2015g.

## Changelog

### 1.27.0 (2016-01-20)
* Add validation function tc.parseable() for date/time strings

### 1.26.0 (2016-01-20)
* Add possibility to change month, weekday, quarter names

Expand Down
31 changes: 28 additions & 3 deletions dist/timezonecomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,9 @@ exports.DEFAULT_FORMAT_OPTIONS = format.DEFAULT_FORMAT_OPTIONS;
var javascript = require("./javascript");
javascript;
exports.DateFunctions = javascript.DateFunctions;
var parse = require("./parse");
parse;
exports.parseable = parse.parseable;
var period = require("./period");
period;
exports.Period = period.Period;
Expand Down Expand Up @@ -2509,7 +2512,7 @@ exports.max = globals.max;



},{"./basics":1,"./datetime":2,"./duration":3,"./format":5,"./globals":6,"./javascript":9,"./period":12,"./timesource":14,"./timezone":16,"./tz-database":18}],5:[function(require,module,exports){
},{"./basics":1,"./datetime":2,"./duration":3,"./format":5,"./globals":6,"./javascript":9,"./parse":11,"./period":12,"./timesource":14,"./timezone":16,"./tz-database":18}],5:[function(require,module,exports){
/**
* Copyright(c) 2014 Spirit IT BV
*
Expand Down Expand Up @@ -3062,7 +3065,7 @@ exports.abs = abs;

},{"./datetime":2,"./duration":3,"assert":19}],"Focm2+":[function(require,module,exports){
module.exports=require(4)
},{"./basics":1,"./datetime":2,"./duration":3,"./format":5,"./globals":6,"./javascript":9,"./period":12,"./timesource":14,"./timezone":16,"./tz-database":18}],"timezonecomplete":[function(require,module,exports){
},{"./basics":1,"./datetime":2,"./duration":3,"./format":5,"./globals":6,"./javascript":9,"./parse":11,"./period":12,"./timesource":14,"./timezone":16,"./tz-database":18}],"timezonecomplete":[function(require,module,exports){
module.exports=require('Focm2+');
},{}],9:[function(require,module,exports){
/**
Expand Down Expand Up @@ -3163,14 +3166,33 @@ var token = require("./token");
var Tokenizer = token.Tokenizer;
var TokenType = token.DateTimeTokenType;
var timeZone = require("./timezone");
/**
* Checks if a given datetime string is according to the given format
* @param dateTimeString The string to test
* @param formatString LDML format string
* @param allowTrailing Allow trailing string after the date+time
* @returns true iff the string is valid
*/
function parseable(dateTimeString, formatString, allowTrailing) {
if (allowTrailing === void 0) { allowTrailing = true; }
try {
parse(dateTimeString, formatString, null, allowTrailing);
return true;
}
catch (e) {
return false;
}
}
exports.parseable = parseable;
/**
* Parse the supplied dateTime assuming the given format.
*
* @param dateTimeString The string to parse
* @param formatString The formatting string to be applied
* @return string
*/
function parse(dateTimeString, formatString, zone) {
function parse(dateTimeString, formatString, zone, allowTrailing) {
if (allowTrailing === void 0) { allowTrailing = true; }
if (!dateTimeString) {
throw new Error("no date given");
}
Expand Down Expand Up @@ -3261,6 +3283,9 @@ function parse(dateTimeString, formatString, zone) {
if (zone) {
result.zone = zone;
}
if (remaining && !allowTrailing) {
throw new Error(util.format("Invalid date '%s' not according to format '%s': trailing characters: '%s'", dateTimeString, formatString, remaining));
}
return result;
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion doc/assets/js/search.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@ <h3 id="does-timezonecomplete-handle-leap-seconds-">Does timezonecomplete handle
<h2 id="current-tz-database-version-">Current TZ database version:</h2>
<p>The version of the included IANA time zone database is 2015g.</p>
<h2 id="changelog">Changelog</h2>
<h3 id="1-27-0-2016-01-20-">1.27.0 (2016-01-20)</h3>
<ul>
<li>Add validation function tc.parseable() for date/time strings</li>
</ul>
<h3 id="1-26-0-2016-01-20-">1.26.0 (2016-01-20)</h3>
<ul>
<li>Add possibility to change month, weekday, quarter names</li>
Expand Down Expand Up @@ -1032,9 +1036,9 @@ <h3 id="1-0-0-2014-06-26-">1.0.0 (2014-06-26)</h3>
</ul>
<h2 id="contributors">Contributors</h2>
<ul>
<li>Rogier Schouten <a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#111;&#58;&#x72;&#46;&#115;&#x63;&#x68;&#x6f;&#117;&#116;&#x65;&#x6e;&#x40;&#x73;&#112;&#105;&#x72;&#105;&#x74;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;">&#x72;&#46;&#115;&#x63;&#x68;&#x6f;&#117;&#116;&#x65;&#x6e;&#x40;&#x73;&#112;&#105;&#x72;&#105;&#x74;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;</a></li>
<li>Daan Wissing <a href="&#109;&#x61;&#x69;&#108;&#116;&#x6f;&#58;&#x64;&#x2e;&#119;&#105;&#x73;&#x73;&#105;&#x6e;&#103;&#64;&#x73;&#x70;&#x69;&#114;&#105;&#x74;&#105;&#116;&#x2e;&#x63;&#x6f;&#109;">&#x64;&#x2e;&#119;&#105;&#x73;&#x73;&#105;&#x6e;&#103;&#64;&#x73;&#x70;&#x69;&#114;&#105;&#x74;&#105;&#116;&#x2e;&#x63;&#x6f;&#109;</a></li>
<li>Peter Kooijmans <a href="&#x6d;&#97;&#105;&#x6c;&#116;&#x6f;&#x3a;&#x70;&#x2e;&#x6b;&#x6f;&#x6f;&#x69;&#x6a;&#109;&#x61;&#110;&#x73;&#x40;&#x73;&#112;&#x69;&#114;&#105;&#116;&#105;&#x74;&#x2e;&#x63;&#111;&#x6d;">&#x70;&#x2e;&#x6b;&#x6f;&#x6f;&#x69;&#x6a;&#109;&#x61;&#110;&#x73;&#x40;&#x73;&#112;&#x69;&#114;&#105;&#116;&#105;&#x74;&#x2e;&#x63;&#111;&#x6d;</a></li>
<li>Rogier Schouten <a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#x3a;&#114;&#x2e;&#115;&#99;&#104;&#111;&#x75;&#116;&#101;&#x6e;&#x40;&#x73;&#x70;&#x69;&#x72;&#105;&#116;&#105;&#116;&#46;&#x63;&#x6f;&#109;">&#114;&#x2e;&#115;&#99;&#104;&#111;&#x75;&#116;&#101;&#x6e;&#x40;&#x73;&#x70;&#x69;&#x72;&#105;&#116;&#105;&#116;&#46;&#x63;&#x6f;&#109;</a></li>
<li>Daan Wissing <a href="&#109;&#97;&#x69;&#x6c;&#116;&#111;&#58;&#x64;&#46;&#119;&#x69;&#x73;&#115;&#x69;&#110;&#x67;&#64;&#115;&#x70;&#105;&#x72;&#105;&#116;&#105;&#116;&#x2e;&#99;&#x6f;&#x6d;">&#x64;&#46;&#119;&#x69;&#x73;&#115;&#x69;&#110;&#x67;&#64;&#115;&#x70;&#105;&#x72;&#105;&#116;&#105;&#116;&#x2e;&#99;&#x6f;&#x6d;</a></li>
<li>Peter Kooijmans <a href="&#109;&#97;&#x69;&#108;&#116;&#111;&#58;&#x70;&#46;&#107;&#x6f;&#111;&#x69;&#106;&#x6d;&#x61;&#x6e;&#x73;&#64;&#115;&#x70;&#x69;&#x72;&#x69;&#x74;&#x69;&#x74;&#46;&#x63;&#x6f;&#x6d;">&#x70;&#46;&#107;&#x6f;&#111;&#x69;&#106;&#x6d;&#x61;&#x6e;&#x73;&#64;&#115;&#x70;&#x69;&#x72;&#x69;&#x74;&#x69;&#x74;&#46;&#x63;&#x6f;&#x6d;</a></li>
</ul>
<h2 id="license">License</h2>
<p>MIT</p>
Expand Down
3 changes: 3 additions & 0 deletions doc/interfaces/_parse_.awaretimestruct.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> zone</h3>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parse" class="tsd-kind-icon">parse</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parseable" class="tsd-kind-icon">parseable</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported">
<a href="../modules/_parse_.html#stripnumber" class="tsd-kind-icon">strip<wbr>Number</a>
</li>
Expand Down
3 changes: 3 additions & 0 deletions doc/interfaces/_parse_.parsenumberresult.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ <h3>remaining</h3>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parse" class="tsd-kind-icon">parse</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parseable" class="tsd-kind-icon">parseable</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported">
<a href="../modules/_parse_.html#stripnumber" class="tsd-kind-icon">strip<wbr>Number</a>
</li>
Expand Down
3 changes: 3 additions & 0 deletions doc/interfaces/_parse_.parsezoneresult.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ <h3>zone</h3>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parse" class="tsd-kind-icon">parse</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="../modules/_parse_.html#parseable" class="tsd-kind-icon">parseable</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported">
<a href="../modules/_parse_.html#stripnumber" class="tsd-kind-icon">strip<wbr>Number</a>
</li>
Expand Down
63 changes: 57 additions & 6 deletions doc/modules/_parse_.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h3>Variables</h3>
<h3>Functions</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-function tsd-parent-kind-external-module"><a href="_parse_.html#parse" class="tsd-kind-icon">parse</a></li>
<li class="tsd-kind-function tsd-parent-kind-external-module"><a href="_parse_.html#parseable" class="tsd-kind-icon">parseable</a></li>
<li class="tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported"><a href="_parse_.html#stripnumber" class="tsd-kind-icon">strip<wbr>Number</a></li>
<li class="tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported"><a href="_parse_.html#stripraw" class="tsd-kind-icon">strip<wbr>Raw</a></li>
<li class="tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported"><a href="_parse_.html#stripzone" class="tsd-kind-icon">strip<wbr>Zone</a></li>
Expand All @@ -105,7 +106,7 @@ <h3>WHITESPACE</h3>
<div class="tsd-signature tsd-kind-icon">WHITESPACE<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Array</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L171">parse.ts:171</a></li>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L193">parse.ts:193</a></li>
</ul>
</aside>
</section>
Expand All @@ -116,13 +117,13 @@ <h2>Functions</h2>
<a name="parse" class="tsd-anchor"></a>
<h3>parse</h3>
<ul class="tsd-signatures tsd-kind-function tsd-parent-kind-external-module">
<li class="tsd-signature tsd-kind-icon">parse<span class="tsd-signature-symbol">(</span>dateTimeString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, formatString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, zone<span class="tsd-signature-symbol">?: </span><a href="../classes/_timezone_.timezone.html" class="tsd-signature-type">TimeZone</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/_parse_.awaretimestruct.html" class="tsd-signature-type">AwareTimeStruct</a></li>
<li class="tsd-signature tsd-kind-icon">parse<span class="tsd-signature-symbol">(</span>dateTimeString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, formatString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, zone<span class="tsd-signature-symbol">?: </span><a href="../classes/_timezone_.timezone.html" class="tsd-signature-type">TimeZone</a>, allowTrailing<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/_parse_.awaretimestruct.html" class="tsd-signature-type">AwareTimeStruct</a></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L54">parse.ts:54</a></li>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L71">parse.ts:71</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -147,12 +148,59 @@ <h5>formatString: <span class="tsd-signature-type">string</span></h5>
<li>
<h5><span class="tsd-flag ts-flagOptional">Optional</span> zone: <a href="../classes/_timezone_.timezone.html" class="tsd-signature-type">TimeZone</a></h5>
</li>
<li>
<h5><span class="tsd-flag ts-flagDefault value">Default value</span> allowTrailing: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> =&nbsp;true</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <a href="../interfaces/_parse_.awaretimestruct.html" class="tsd-signature-type">AwareTimeStruct</a></h4>
<p>string</p>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-function tsd-parent-kind-external-module">
<a name="parseable" class="tsd-anchor"></a>
<h3>parseable</h3>
<ul class="tsd-signatures tsd-kind-function tsd-parent-kind-external-module">
<li class="tsd-signature tsd-kind-icon">parseable<span class="tsd-signature-symbol">(</span>dateTimeString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, formatString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, allowTrailing<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L55">parse.ts:55</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Checks if a given datetime string is according to the given format</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>dateTimeString: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>The string to test</p>
</div>
</li>
<li>
<h5>formatString: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>LDML format string</p>
</div>
</li>
<li>
<h5><span class="tsd-flag ts-flagDefault value">Default value</span> allowTrailing: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> =&nbsp;true</span></h5>
<div class="tsd-comment tsd-typography">
<p>Allow trailing string after the date+time</p>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
<p>true iff the string is valid</p>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported">
<a name="stripnumber" class="tsd-anchor"></a>
<h3>strip<wbr>Number</h3>
Expand All @@ -163,7 +211,7 @@ <h3>strip<wbr>Number</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L150">parse.ts:150</a></li>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L172">parse.ts:172</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -186,7 +234,7 @@ <h3>strip<wbr>Raw</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L190">parse.ts:190</a></li>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L212">parse.ts:212</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -212,7 +260,7 @@ <h3>strip<wbr>Zone</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L173">parse.ts:173</a></li>
<li>Defined in <a href="https://github.com/SpiritIT/timezonecomplete/blob/master/lib/parse.ts#L195">parse.ts:195</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -297,6 +345,9 @@ <h4 class="tsd-returns-title">Returns <a href="../interfaces/_parse_.parsezonere
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="_parse_.html#parse" class="tsd-kind-icon">parse</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module">
<a href="_parse_.html#parseable" class="tsd-kind-icon">parseable</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-external-module tsd-is-not-exported">
<a href="_parse_.html#stripnumber" class="tsd-kind-icon">strip<wbr>Number</a>
</li>
Expand Down
Loading

0 comments on commit a61f573

Please sign in to comment.