Skip to content
Open
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
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: GQiHTVmmp97RofjFzkjPWhnfYnkny2Gnh
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
coverage/coverage.html
coverage
node_modules
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- '0.10'
script:
- 'npm run coveralls'
notifications:
email:
on_success: never
on_failure: always
68 changes: 32 additions & 36 deletions GedcomXDate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GedcomXDate = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var util = require('util'),
Simple = require('./simple.js');

Expand Down Expand Up @@ -1494,46 +1494,40 @@ if (typeof Object.create === 'function') {
// shim for using process in browser

var process = module.exports = {};
var queue = [];
var draining = false;

process.nextTick = (function () {
var canSetImmediate = typeof window !== 'undefined'
&& window.setImmediate;
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener
;

if (canSetImmediate) {
return function (f) { return window.setImmediate(f) };
function drainQueue() {
if (draining) {
return;
}

if (canPost) {
var queue = [];
window.addEventListener('message', function (ev) {
var source = ev.source;
if ((source === window || source === null) && ev.data === 'process-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}, true);

return function nextTick(fn) {
queue.push(fn);
window.postMessage('process-tick', '*');
};
draining = true;
var currentQueue;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
var i = -1;
while (++i < len) {
currentQueue[i]();
}
len = queue.length;
}

return function nextTick(fn) {
setTimeout(fn, 0);
};
})();
draining = false;
}
process.nextTick = function (fun) {
queue.push(fun);
if (!draining) {
setTimeout(drainQueue, 0);
}
};

process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};

function noop() {}

Expand All @@ -1547,13 +1541,14 @@ process.emit = noop;

process.binding = function (name) {
throw new Error('process.binding is not supported');
}
};

// TODO(shtylman)
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };

},{}],11:[function(require,module,exports){
module.exports = function isBuffer(arg) {
Expand Down Expand Up @@ -2151,5 +2146,6 @@ function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

}).call(this,require("FWaASH"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./support/isBuffer":11,"FWaASH":10,"inherits":9}]},{},[3])
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./support/isBuffer":11,"_process":10,"inherits":9}]},{},[3])(3)
});
49 changes: 29 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[![Build Status](https://travis-ci.org/genealogysystems/gedcomx-date-js.svg?branch=build)](https://travis-ci.org/genealogysystems/gedcomx-date-js)
[![Coverage Status](https://coveralls.io/repos/genealogysystems/gedcomx-date-js/badge.svg)](https://coveralls.io/r/genealogysystems/gedcomx-date-js)
[![Dependency Status](https://david-dm.org/genealogysystems/gedcomx-date-js.svg)](https://david-dm.org/genealogysystems/gedcomx-date-js)
[![devDependency Status](https://david-dm.org/genealogysystems/gedcomx-date-js/dev-status.svg)](https://david-dm.org/genealogysystems/gedcomx-date-js#info=devDependencies)

# GedcomX-Date

A GEDCOM-X Date Library for Javascript, fully compliant with the [spec](https://github.com/FamilySearch/gedcomx/blob/master/specifications/date-format-specification.md).

# Usage
````javascript

```js
var GedcomXDate = require('gedcomx-date');

var single = new GedcomXDate('+1900-01-01');
Expand Down Expand Up @@ -38,41 +45,43 @@ var halfDuration = GedcomXDate.multiplyDuration(newDuration, .5);

console.log(newDuration.toFormalString());
// P57Y1M
````
```

## Node.js

You can install GedcomX-Date by cloning this repository or by using npm.
````bash
```bash
npm install gedcomx-date
````
```

## Browser

Download [GedcomXDate.js](GedcomXDate.js) and enjoy.
(Packaged with love by [browserify](http://browserify.org/))

# Tests

There is a very comprehensive test suite.
````bash
# To run the tests cd to the repo directory and run
mocha

# To generate the code coverage run
./coverage/generate.sh
````
Install [mocha](http://visionmedia.github.io/mocha/) and [jscoverage](https://github.com/visionmedia/node-jscoverage) globally before runnings tests and generating coverage.
```bash
# Run tests
npm test

# Generate code coverage
npm run coverage
```

# Reference

When you create a new GedcomXDate you pass in a formal date string into the contructor.
It will parse and validate the string, and return an object representation of it.
If there is a parsing error GedcomXDate with throw an error.

## Single
````javascript

```js
var date = new GedcomXDate('A+2000-01-01');
// date will be a Single Date
````
```

### getType()
Returns the `string` 'single'.
Expand Down Expand Up @@ -110,13 +119,13 @@ Returns the formal GedcomX representation as a `string`.

## Range
A range has three components, start, end, and duration
````javascript
```js
var date = GedcomXDate('A+1000-01-01/+2000-12-31');

// date.start will be a simple date
// date.end will be a simple date
// date.duration will be a duration
````
```

### getType()
Returns the `string` 'range'.
Expand All @@ -139,9 +148,9 @@ Returns the formal GedcomX representation as a `string`.

## Recurring
A Recurring date is the same as a Range with a few more methods.
````javascript
```js
var date = GedcomXDate('R2/+1000-01-01/+2000-12-31');
````
```

### getType()
Returns the `string` 'recurring'.
Expand All @@ -164,11 +173,11 @@ Returns the formal GedcomX representation as a `string`.

## Duration
Represents a duration of time.
````javascript
```js
var date = GedcomXDate('A+1000-01-01/P100Y');

var duration = date.getDuration();
````
```

### getType()
Returns the `string` 'duration'.
Expand Down
10 changes: 0 additions & 10 deletions coverage/generate.sh

This file was deleted.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
"main": "lib/gedcomx-date.js",
"scripts": {
"test": "mocha",
"build": "./node_modules/browserify/bin/cmd.js lib/gedcomx-date.js -s GedcomXDate -o GedcomXDate.js"
"build": "browserify lib/gedcomx-date.js -s GedcomXDate -o GedcomXDate.js",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"dependencies": {},
"devDependencies": {
"chai": "~1.9.1",
"browserify": "~3.46.0"
"browserify": "9.0.8",
"chai": "2.2.0",
"coveralls": "2.11.2",
"istanbul": "0.3.13",
"mocha": "2.2.4"
}
}
5 changes: 2 additions & 3 deletions test/approximate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Approximate = require(path.join(libPath, 'approximate.js'));
Approximate = require(path.join('../lib', 'approximate.js'));

describe('Approximate', function(){

Expand Down
5 changes: 2 additions & 3 deletions test/duration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Duration = require(path.join(libPath, 'duration.js'));
Duration = require(path.join('../lib', 'duration.js'));

describe('Duration', function(){

Expand Down
15 changes: 7 additions & 8 deletions test/gedcomx-date.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
fs = require('fs'),
expect = require('chai').expect,
Simple = require(path.join(libPath, 'simple.js')),
Approximate = require(path.join(libPath, 'approximate.js')),
Recurring = require(path.join(libPath, 'recurring.js')),
Duration = require(path.join(libPath, 'duration.js')),
Range = require(path.join(libPath, 'range.js')),
GedcomXDate = require(path.join(libPath, 'gedcomx-date.js'));
Simple = require(path.join('../lib', 'simple.js')),
Approximate = require(path.join('../lib', 'approximate.js')),
Recurring = require(path.join('../lib', 'recurring.js')),
Duration = require(path.join('../lib', 'duration.js')),
Range = require(path.join('../lib', 'range.js')),
GedcomXDate = require(path.join('../lib', 'gedcomx-date.js'));

describe('GedcomXDate', function(){

Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts

This file was deleted.

10 changes: 4 additions & 6 deletions test/range.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Simple = require(path.join(libPath, 'simple.js')),
Approximate = require(path.join(libPath, 'approximate.js')),
Duration = require(path.join(libPath, 'duration.js')),
Range = require(path.join(libPath, 'range.js'));
Simple = require(path.join('../lib', 'simple.js')),
Duration = require(path.join('../lib', 'duration.js')),
Range = require(path.join('../lib', 'range.js'));

describe('Range', function(){

Expand Down
7 changes: 2 additions & 5 deletions test/recurring.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Simple = require(path.join(libPath, 'simple.js')),
Approximate = require(path.join(libPath, 'approximate.js')),
Recurring = require(path.join(libPath, 'recurring.js'));
Recurring = require(path.join('../lib', 'recurring.js'));

describe('Recurring', function(){
describe("#(start, end)", function(){
Expand Down
5 changes: 2 additions & 3 deletions test/simple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Simple = require(path.join(libPath, 'simple.js'));
Simple = require(path.join('../lib', 'simple.js'));

describe('Simple', function(){

Expand Down
5 changes: 2 additions & 3 deletions test/util-global.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
var path = require('path'),
expect = require('chai').expect,
Util = require(path.join(libPath, 'util-global.js'));
Util = require(path.join('../lib', 'util-global.js'));

describe('Util-Global', function(){

Expand Down
14 changes: 5 additions & 9 deletions test/util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib',
path = require('path'),
fs = require('fs'),
var path = require('path'),
expect = require('chai').expect,
Simple = require(path.join(libPath, 'simple.js')),
Approximate = require(path.join(libPath, 'approximate.js')),
Recurring = require(path.join(libPath, 'recurring.js')),
Duration = require(path.join(libPath, 'duration.js')),
Range = require(path.join(libPath, 'range.js')),
GedcomXDate = require(path.join(libPath, 'gedcomx-date.js'));
Simple = require(path.join('../lib', 'simple.js')),
Approximate = require(path.join('../lib', 'approximate.js')),
Duration = require(path.join('../lib', 'duration.js')),
GedcomXDate = require(path.join('../lib', 'gedcomx-date.js'));

describe('Util', function(){

Expand Down