Skip to content

Commit

Permalink
Update with new utilx
Browse files Browse the repository at this point in the history
  • Loading branch information
Xotic750 committed Jan 6, 2014
1 parent 6f63e58 commit 7fc2a6a
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 246 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -12,7 +12,7 @@ Master

[![browser support](https://ci.testling.com/Xotic750/astrodate.png)](https://ci.testling.com/Xotic750/astrodate 'Browser support on Testling CI')

#[AstroDate 0.7.2](http://xotic750.github.io/astrodate/)
#[AstroDate 0.7.3](http://xotic750.github.io/astrodate/)
###### Graham Fairweather <xotic750@gmail.com>

Still very much work in progress, so there are [bugs](https://github.com/Xotic750/astrodate/issues "Issues") and the API has not been fully defined (or documented) and is subject to major changes.
Expand Down
138 changes: 69 additions & 69 deletions docs/AstroDate.html

Large diffs are not rendered by default.

84 changes: 31 additions & 53 deletions docs/astrodate.js.html
Expand Up @@ -27,7 +27,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
<article>
<pre class="prettyprint source linenums"><code>/**
* @file {@link http://xotic750.github.io/astrodate/ AstroDate}. Javascript Date object with Astronomy in mind..
* @version 0.7.2
* @version 0.7.3
* @author Graham Fairweather &lt;xotic750@gmail.com>
* @copyright Copyright (c) 2013 Graham Fairweather
* @license {@link &lt;http://www.gnu.org/licenses/gpl-3.0.html> GPL3}
Expand Down Expand Up @@ -237,7 +237,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
}
});

var VERSION = '0.7.2',
var VERSION = '0.7.3',
/**
* For normalising options.
* @private
Expand Down Expand Up @@ -328,6 +328,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
invalidISOCharsRx = new RegExp('[^\\d\\-+WT Z:,\\.]'),
replaceTokenRX = new RegExp('([^\\\']+)|(\\\'[^\\\']+\\\')', 'g'),
unmatchedTokenRx = new RegExp('[^a-z]', 'gi'),
bnOffsetRx = new RegExp('^([\\-+])?(\\d{1,2}):(\\d{2})(?::(\\d{2}))?$'),
//j2000 = [2000, 1, 1, 11, 58, 55, 816],
/**
* For holding CLDR language specific data.
Expand Down Expand Up @@ -378,22 +379,6 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
utilx.deepFreeze(widthTypes);
utilx.deepFreeze(formatTypes);

/*
function InvalidError(message) {
//this.name = "InvalidError";
this.message = message || "";
}

InvalidError.prototype = new Error();

function NotImplimentedError(message) {
//this.name = "NotImplementedError";
this.message = message || "";
}

NotImplimentedError.prototype = new Error();
*/

function isGregorianLeapYear(struct) {
return struct.year.mod(400).isZero() || (!struct.year.mod(100).isZero() &amp;&amp; struct.year.mod(4).isZero());
}
Expand Down Expand Up @@ -930,7 +915,6 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
function bnOffset(value) {
var val,
bn,
rx,
off;

if (utilx.isNumber(value) || utilx.isString(value)) {
Expand All @@ -947,9 +931,8 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
} else if (utilx.strictEqual(val, 'Z') || utilx.strictEqual(val, 'UTC') || utilx.strictEqual(val, 'GMT')) {
bn = BigNumber.zero();
} else {
rx = /^([\-+])?(\d{1,2}):(\d{2})(?::(\d{2}))?$/;
if (rx.test(val)) {
off = val.match(rx);
if (bnOffsetRx.test(val)) {
off = val.match(bnOffsetRx);
bn = offsetToSeconds(off[2], off[3], off[4]).times(toSignMultipler(off[1] || '+')).neg();
} else {
bn = bnGetTimezoneOffset();
Expand All @@ -968,7 +951,8 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
bn,
dim;

if (utilx.isNumber(value) || utilx.isString(value) || (value &amp;&amp; value instanceof BigNumber)) {
if (utilx.isNumber(value) || utilx.isString(value) ||
(utilx.isTypeObject(value) &amp;&amp; utilx.objectInstanceOf(value, BigNumber))) {
bn = new BigNumber(value);
} else {
bn = new BigNumber(NaN);
Expand Down Expand Up @@ -1106,7 +1090,8 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
bn,
dim;

if (utilx.isNumber(value) || utilx.isString(value) || (value &amp;&amp; value instanceof BigNumber)) {
if (utilx.isNumber(value) || utilx.isString(value) ||
(utilx.isTypeObject(value) &amp;&amp; utilx.objectInstanceOf(value, BigNumber))) {
bn = new BigNumber(value);
} else {
bn = new BigNumber(NaN);
Expand Down Expand Up @@ -2961,7 +2946,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
* @return {array.&lt;string>}
*/
function splitUnderscore(string) {
return string.split('_');
return utilx.stringSplit(string, '_');
}

canonicalizeLocaleRx = new RegExp('^([a-z]{2,3}|[a-z]{2,3}[\\-_][a-z]{2}|' +
Expand Down Expand Up @@ -3011,7 +2996,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
}
}

return val.join('_');
return utilx.arrayJoin(val, '_');
}

/**
Expand Down Expand Up @@ -3054,11 +3039,11 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
}

if (utilx.isUndefined(lookup) &amp;&amp; !utilx.isUndefined(region)) {
lookup = likelySubtags[[lang, region].join('_')];
lookup = likelySubtags[utilx.arrayJoin([lang, region], '_')];
}

if (utilx.isUndefined(lookup) &amp;&amp; !utilx.isUndefined(script)) {
lookup = likelySubtags[[lang, script].join('_')];
lookup = likelySubtags[utilx.arrayJoin([lang, script], '_')];
}

if (utilx.isUndefined(lookup)) {
Expand All @@ -3072,7 +3057,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
}

if (utilx.isUndefined(lookup) &amp;&amp; !utilx.isUndefined(script)) {
lookup = likelySubtags[['und', script].join('_')];
lookup = likelySubtags[utilx.arrayJoin(['und', script], '_')];
}
}
}
Expand Down Expand Up @@ -3102,7 +3087,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
loaded = lang;
} else {
firstSplit = splitUnderscore(lookupLocale(locale));
lang = [utilx.arrayFirst(firstSplit), utilx.arrayLast(firstSplit)].join('_');
lang = utilx.arrayJoin([utilx.arrayFirst(firstSplit), utilx.arrayLast(firstSplit)], '_');
if (!utilx.isUndefined(languages[lang])) {
loaded = lang;
} else {
Expand Down Expand Up @@ -3315,7 +3300,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
// ISO 8601 time zone formats.
function formatIsoTimeZone(struct, lang, withZ, format, optional) {
var timeZoneNames = languages[lang].dates.timeZoneNames,
offsetFormats = timeZoneNames.hourFormat.split(';'),
offsetFormats = utilx.stringSplit(timeZoneNames.hourFormat, ';'),
offsetFormat,
offset,
pattern;
Expand All @@ -3333,7 +3318,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
offsetFormat = offsetFormat.replace(/([\-+])H:/i, '$1HH:');
if (utilx.strictEqual(format, 'basic')) {
if (utilx.strictEqual(optional, true) &amp;&amp; offset.minute.isZero()) {
offsetFormat = utilx.arrayFirst(offsetFormat.split(':'));
offsetFormat = utilx.arrayFirst(utilx.stringSplit(offsetFormat, ':'));
} else {
offsetFormat = offsetFormat.replace(':', '');
}
Expand Down Expand Up @@ -3364,7 +3349,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
// ISO 8601 time zone formats.
function formatIsoTimeZoneSeconds(struct, lang, withZ, format, optional) {
var timeZoneNames = languages[lang].dates.timeZoneNames,
offsetFormats = timeZoneNames.hourFormat.split(';'),
offsetFormats = utilx.stringSplit(timeZoneNames.hourFormat, ';'),
offsetFormat,
offset,
pattern;
Expand All @@ -3382,9 +3367,9 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
offsetFormat = offsetFormat.replace(/([\-+])H:/i, '$1HH:') + ':ss';
if (utilx.strictEqual(format, 'basic')) {
if (utilx.strictEqual(optional, true) &amp;&amp; offset.second.isZero()) {
offsetFormat = offsetFormat.split(':');
offsetFormat = utilx.stringSplit(offsetFormat, ':');
offsetFormat.pop();
offsetFormat = offsetFormat.join('');
offsetFormat = utilx.arrayJoin(offsetFormat, '');
} else {
offsetFormat = offsetFormat.replace(':', '');
}
Expand Down Expand Up @@ -3414,7 +3399,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
// The localized GMT format.
function formatLocalisedGMT(struct, lang, requestedShort) {
var timeZoneNames = languages[lang].dates.timeZoneNames,
offsetFormats = timeZoneNames.hourFormat.split(';'),
offsetFormats = utilx.stringSplit(timeZoneNames.hourFormat, ';'),
offsetFormat,
offset,
pattern;
Expand All @@ -3436,7 +3421,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
}

if (requestedShort &amp;&amp; offset.minute.isZero()) {
offsetFormat = utilx.arrayFirst(offsetFormat.split(':'));
offsetFormat = utilx.arrayFirst(utilx.stringSplit(offsetFormat, ':'));
}

pattern = replaceToken(offsetFormat, 'H{1,2}', offset.hour);
Expand Down Expand Up @@ -3618,7 +3603,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
* new AstroDate('-10', '5', '7', {julian: true}); // year -10 of the Julian Calendar
*/
function AstroDate() {
var args = arguments,
var args = utilx.arraySlice(arguments),
input = arguments,
argsLength = args.length,
isJulian = false,
Expand Down Expand Up @@ -3860,12 +3845,12 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
isJulian = true;
}

struct = arrayToStruct(utilx.argumentsSlice(args, 0, -1), isJulian);
struct = arrayToStruct(utilx.arraySlice(args, 0, -1), isJulian);
if (isJulian) {
struct = julianToGregorian(struct);
}
} else {
struct = arrayToStruct(utilx.argumentsSlice(args, 0, args.length), isJulian);
struct = arrayToStruct(utilx.arraySlice(args, 0, args.length), isJulian);
}

if (utilx.isUndefined(args[8]) &amp;&amp; !utilx.isUndefined(opts.offset)) {
Expand Down Expand Up @@ -5085,7 +5070,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod

if (utilx.isUndefined(date)) {
if (this.isValid()) {
val = new Date(parseInt(this.getTime(), 10));
val = new Date(utilx.toNumber(this.getTime()));
} else {
val = new Date(NaN);
}
Expand Down Expand Up @@ -5184,7 +5169,7 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod

val = gregorianToJd(toUT(struct)).toFixed(BigNumber.config().DECIMAL_PLACES);
}
} else if (utilx.isNumber(jd) || utilx.isString(jd) || (jd &amp;&amp; jd instanceof BigNumber)) {
} else if (utilx.isNumber(jd) || (utilx.isString(jd) &amp;&amp; !utilx.isEmptyString(jd))) {
val = this.setter('struct', jdToGregorian(jd));
} else {
throw new TypeError(jd);
Expand Down Expand Up @@ -5373,22 +5358,15 @@ <h1 class="page-title">Source: /home/graham/source_projects/astrodate/lib/astrod
var struct,
val;

if (utilx.isUndefined(jsonString)) {
if (typeof JSON === 'object' &amp;&amp; utilx.isFunction(JSON.stringify)) {
val = utilx.jsonStringify(this.object());
}
} else if (utilx.isString(jsonString)) {
if (typeof JSON === 'object' &amp;&amp; utilx.isFunction(JSON.parse)) {
struct = objectToStruct(utilx.jsonParse(jsonString), this.isJulian());
}

if (utilx.isString(jsonString) &amp;&amp; !utilx.isEmptyString(jsonString)) {
struct = objectToStruct(utilx.jsonParse(jsonString), this.isJulian());
if (!isValid(struct)) {
throw new SyntaxError(struct);
}

val = this.setter('struct', struct);
} else {
throw new TypeError(jsonString);
val = utilx.jsonStringify(this.object());
}

return val;
Expand Down Expand Up @@ -27669,7 +27647,7 @@ <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-a
<br clear="both">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Wed Jan 01 2014 04:33:43 GMT+0100 (CET)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Mon Jan 06 2014 18:17:00 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Expand Up @@ -48,8 +48,8 @@ <h3> </h3>
<p><a href="https://coveralls.io/r/Xotic750/astrodate?branch=master" title="Coverage status on Coveralls"><img src="https://coveralls.io/repos/Xotic750/astrodate/badge.png?branch=master" alt="Coverage Status"></a></p>
<p><a href="http://badge.fury.io/js/astrodate" title="Current NPM release"><img src="https://badge.fury.io/js/astrodate.png" alt="NPM version"></a></p>
<p><a href="https://ci.testling.com/Xotic750/astrodate" title="Browser support on Testling CI"><img src="https://ci.testling.com/Xotic750/astrodate.png" alt="browser support"></a></p>
<h1 id="-astrodate-0-7-2-http-xotic750-github-io-astrodate-"><a href="http://xotic750.github.io/astrodate/">AstroDate 0.7.2</a></h1>
<h6 id="graham-fairweather-xotic750-gmail-com-">Graham Fairweather <a href="&#109;&#x61;&#105;&#108;&#x74;&#x6f;&#x3a;&#x78;&#x6f;&#x74;&#105;&#x63;&#55;&#x35;&#48;&#x40;&#x67;&#109;&#97;&#105;&#108;&#46;&#x63;&#111;&#x6d;">&#x78;&#x6f;&#x74;&#105;&#x63;&#55;&#x35;&#48;&#x40;&#x67;&#109;&#97;&#105;&#108;&#46;&#x63;&#111;&#x6d;</a></h6>
<h1 id="-astrodate-0-7-3-http-xotic750-github-io-astrodate-"><a href="http://xotic750.github.io/astrodate/">AstroDate 0.7.3</a></h1>
<h6 id="graham-fairweather-xotic750-gmail-com-">Graham Fairweather <a href="&#x6d;&#x61;&#x69;&#x6c;&#116;&#111;&#x3a;&#120;&#111;&#x74;&#x69;&#x63;&#55;&#53;&#48;&#x40;&#x67;&#x6d;&#x61;&#105;&#108;&#x2e;&#99;&#111;&#x6d;">&#120;&#111;&#x74;&#x69;&#x63;&#55;&#53;&#48;&#x40;&#x67;&#x6d;&#x61;&#105;&#108;&#x2e;&#99;&#111;&#x6d;</a></h6>
<p>Still very much work in progress, so there are <a href="https://github.com/Xotic750/astrodate/issues" title="Issues">bugs</a> and the API has not been fully defined (or documented) and is subject to major changes.</p>
<p>The idea behind the project is to not rely on Javascript's rather flaky <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date" title="Date Object reference"><code>Date</code></a> object, give better accuracy, flexibility and be cross-browser.</p>
<p>Besides the standard <a href="http://en.wikipedia.org/wiki/Gregorian_calendar" title="Wikipedia">Gregorian calendar</a>, the <a href="http://en.wikipedia.org/wiki/Julian_calendar" title="Wikipedia">Julian calendar</a> is also available. This allows for AstroDate to be used in astronomical calculations.
Expand Down Expand Up @@ -137,7 +137,7 @@ <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-a
<br clear="both">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Wed Jan 01 2014 04:33:43 GMT+0100 (CET)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Mon Jan 06 2014 18:17:00 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/module-astrodate.html
Expand Up @@ -47,7 +47,7 @@ <h2>


<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.7.2</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>0.7.3</li></ul></dd>



Expand Down Expand Up @@ -129,7 +129,7 @@ <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-a
<br clear="both">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Wed Jan 01 2014 04:33:43 GMT+0100 (CET)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha3</a> on Mon Jan 06 2014 18:17:00 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
Expand Down

0 comments on commit 7fc2a6a

Please sign in to comment.