Releases: doniseferi/suntimes
v6.0.2
v6.0.1
chore(release): 6.0.1
v6.0.0
chore(release): 6.0.0
v5.0.1
chore(release): 5.0.1
v5.0.0
chore(release): 5.0.0
v4.1.6
chore(release): 4.1.6
v4.1.5
chore(release): 4.1.5
v4.1.2
Type definition file included
v4.0.1
- Readme updated d216f97
Api Changes
- Runs on node or web browsers
- None
Changes
- Javascript module type is now UMD
- Bundled and minified into one file named
suntimes.js
suntimes.js
file minified to 9Kb with all comments kept- All comments kept
Test Results
TOC
- Scientific decimal time to time
- Get all dates for a year
- Get day of the year
- Declination of the sun
- Declination Of The Sun Factory
- Equation of time
- Index
- Get Noon Time Utcs
- Trigonometry objects
- Angle conversions
The correct date time utc of all expected points of a date are returned with a +/- 60 second accuracy.
[testModel(new Date(2019, 0, 1), _utcJanNoon["default"], noonWrapper), testModel(new Date(2019, 6, 1), _utcJulyNoon["default"], noonWrapper), testModel(new Date(2019, 0, 1), _utcJanSunrise["default"], _index.getSunriseDateTimeUtc), testModel(new Date(2019, 6, 1), _utcJulySunrise["default"], _index.getSunriseDateTimeUtc), testModel(new Date(2019, 0, 1), _utcJanSunset["default"], _index.getSunsetDateTimeUtc), testModel(new Date(2019, 6, 1), _utcJulySunset["default"], _index.getSunsetDateTimeUtc), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getAstronomicalDawnStartDateTimeUtc, 'ExpectedAstronomicalDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getNauticalDawnStartDateTimeUtc, 'ExpectedNauticalDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getCivilDawnStartDateTimeUtc, 'ExpectedCivilDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getAstronomicalDuskStartDateTimeUtc, 'ExpectedAstronomicalDuskUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getNauticalDuskStartDateTimeUtc, 'ExpectedNauticalDuskUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getCivilDuskStartDateTimeUtc, 'ExpectedCivilDuskUtc')].forEach(function (testModel) {
return assertTimesAreCloseToDelta(testModel);
});
Scientific decimal time to time
returns hours.
_chai.assert.equal((0, _index.toTime)(1).hours, 1);
_chai.assert.equal((0, _index.toTime)(10).hours, 10);
_chai.assert.equal((0, _index.toTime)(100).hours, 100);
_chai.assert.equal((0, _index.toTime)(100.9).hours, 100);
_chai.assert.equal((0, _index.toTime)(10.9).hours, 10);
_chai.assert.equal((0, _index.toTime)(1.9).hours, 1);
returns minutes.
_chai.assert.equal((0, _index.toTime)(0.0166667).minutes, 1);
_chai.assert.equal((0, _index.toTime)(0.1666667).minutes, 10);
_chai.assert.equal((0, _index.toTime)(0.1666667).minutes, 10);
_chai.assert.equal((0, _index.toTime)(0.5).minutes, 30);
_chai.assert.equal((0, _index.toTime)(0.983335).minutes, 59);
returns seconds.
_chai.assert.equal((0, _index.toTime)(0.000277778).seconds, 1);
_chai.assert.equal((0, _index.toTime)(0.00277778).seconds, 10);
_chai.assert.equal((0, _index.toTime)(0.008333361).seconds, 30);
_chai.assert.equal((0, _index.toTime)(0.0138889).seconds, 50);
_chai.assert.equal((0, _index.toTime)(0.0163889).seconds, 59);
_chai.assert.equal((0, _index.toTime)(0.0166667).seconds, 0);
returns milliseconds.
_chai.assert.equal((0, _index.toTime)(0.0002775).milliseconds, 999);
_chai.assert.equal((0, _index.toTime)(0.000100278).milliseconds, 361);
_chai.assert.equal((0, _index.toTime)(0.000277778).milliseconds, 0);
_chai.assert.equal((0, _index.toTime)(0.000234167).milliseconds, 843);
returns the complete every time unit.
var decimalTime = 23.756;
var actual = (0, _index.toTime)(decimalTime);
_chai.assert.equal(actual.hours, 23);
_chai.assert.equal(actual.minutes, 45);
_chai.assert.equal(actual.seconds, 21);
_chai.assert.equal(actual.milliseconds, 600);
throws an exception when the value is null, undefined or not a number.
_chai.assert["throws"](function () {
return (0, _index.toTime)(null);
});
_chai.assert["throws"](function () {
return (0, _index.toTime)(undefined);
});
_chai.assert["throws"](function () {
return (0, _index.toTime)('One');
});
_chai.assert["throws"](function () {
return (0, _index.toTime)('');
});
Get all dates for a year
returns every distinct date for a non leap year.
var expectedYear = 2001;
var allDates = (0, _dateTestUtilities["default"])(expectedYear);
var distinctDates = allDates.map(function (s) {
return s.toString();
}).filter(function (s, i, a) {
return a.indexOf(s) === i;
}).map(function (s) {
return new Date(s);
});
var uniqueYears = _toConsumableArray(new Set(allDates.map(function (x) {
return x.getFullYear();
})));
var expectedNumberOfUniqueYears = 1;
_chai.assert.equal(allDates.length, distinctDates.length);
_chai.assert.equal(uniqueYears.length, expectedNumberOfUniqueYears);
_chai.assert.equal(uniqueYears[0], expectedYear);
returns every distinct date for a leap year.
var expectedYear = 2000;
var allDates = (0, _dateTestUtilities["default"])(expectedYear);
var distinctDates = allDates.map(function (s) {
return s.toString();
}).filter(function (s, i, a) {
return a.indexOf(s) === i;
}).map(function (s) {
return new Date(s);
});
var uniqueYears = _toConsumableArray(new Set(allDates.map(function (x) {
return x.getFullYear();
})));
var expectedNumberOfUniqueYears = 1;
_chai.assert.equal(allDates.length, distinctDates.length);
_chai.assert.equal(uniqueYears.length, expectedNumberOfUniqueYears);
_chai.assert.equal(uniqueYears[0], expectedYear);
Get day of the year
returns the correct day of the year.
_getDayOfTheYearTestData["default"].forEach(function (data) {
var date = data.date,
expectedDayOfTheYear = data.expectedDayOfTheYear;
var actualDayOfTheYearResult = (0, _index.getDayOfTheYear)(new Date(date));
_chai.assert.equal(actualDayOfTheYearResult, expectedDayOfTheYear);
});
returns day of the year for every day on a leap year.
var allDaysOnALeapYear = (0, _dateTestUtilities["default"])(1944);
allDaysOnALeapYear.forEach(function (date) {
var expectedDayOfTheYear = allDaysOnALeapYear.indexOf(date) + 1;
var actualDayOfTheYear = (0, _index.getDayOfTheYear)(date);
_chai.assert.equal(actualDayOfTheYear, expectedDayOfTheYear);
});
returns day of the year for every day on non leap year.
var allDaysOnALeapYear = (0, _dateTestUtilities["default"])(2017);
allDaysOnALeapYear.forEach(function (date) {
var expectedDayOfTheYear = allDaysOnALeapYear.indexOf(date) + 1;
var actualDayOfTheYear = (0, _index.getDayOfTheYear)(date);
_chai.assert.equal(actualDayOfTheYear, expectedDayOfTheYear);
});
throws exception when an invalid date is passed.
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)(undefined);
}, 'Please provide a valid date');
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)(null);
}, 'Please provide a valid date');
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)();
}, 'Please provide a valid date');
Declination of the sun
returns the correct value in degrees within +/- 0.4 degree accuracy.
_declinationOfTheSunTestData["default"].forEach(function (data) {
var date = data.date,
declination = data.declination;
var result = (0, _index["default"])(new Date(date));
var difference = result - declination;
_chai.assert.closeTo(difference, 0, 0.4);
});
throws an error if an invalid date is passed in.
var expectedErrorMessage = 'Please provide a valid date';
_chai.assert["throws"](function () {
return (0, _index["default"])(null);
}, expectedErrorMessage);
_chai.assert["throws"](function () {
return (0, _index["default"])(undefined);
}, expectedErrorMessage);
_chai.assert["throws"](function () {
return (0, _index["default"])();
}, expectedErrorMessage);
Declination Of The Sun Factory
throws an exception if you do not pass in all parameters.
var stub = function stub() {
return 1;
};
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(null, stub, stub, stub);
}, 'Please provide a function for sine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, null, stub, stub);
}, 'Please provide a function for cosine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, null, stub);
}, 'Please provide a function for arcsine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, stub, null);
}, 'Please provide a function for getDayOfTheYear.');
returns a get declination of the sun function.
var stub = function stub() {
return 1;
};
_chai.assert.typeOf(function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, stub, stub).getDeclinationOfTheSun;
}, 'function');
Equation of time
returns the correct equation of time with a margin of error of +/- 4 seconds.
_equationOfTimeTestData["default"].forEach(function (expectedResult) {
var eot = expectedResult.eot,
date = expectedResult.date;
var actual = (0, _index.equationOfTime)(new Date(date));
var difference = eot * 60 - actual * 60;
_chai.assert.closeTo(difference, 0, 3.99);
});
`...
v4.0.0
Api Changes
- None
Changes
- Javascript module type is now UMD
- Bundled and minified into one file named
suntimes.js
suntimes.js
file minified to 9Kb with all comments kept- All comments kept
Test Results
TOC
- Scientific decimal time to time
- Get all dates for a year
- Get day of the year
- Declination of the sun
- Declination Of The Sun Factory
- Equation of time
- Index
- Get Noon Time Utcs
- Trigonometry objects
- Angle conversions
The correct date time utc of all expected points of a date are returned with a +/- 60 second accuracy.
[testModel(new Date(2019, 0, 1), _utcJanNoon["default"], noonWrapper), testModel(new Date(2019, 6, 1), _utcJulyNoon["default"], noonWrapper), testModel(new Date(2019, 0, 1), _utcJanSunrise["default"], _index.getSunriseDateTimeUtc), testModel(new Date(2019, 6, 1), _utcJulySunrise["default"], _index.getSunriseDateTimeUtc), testModel(new Date(2019, 0, 1), _utcJanSunset["default"], _index.getSunsetDateTimeUtc), testModel(new Date(2019, 6, 1), _utcJulySunset["default"], _index.getSunsetDateTimeUtc), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getAstronomicalDawnStartDateTimeUtc, 'ExpectedAstronomicalDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getNauticalDawnStartDateTimeUtc, 'ExpectedNauticalDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getCivilDawnStartDateTimeUtc, 'ExpectedCivilDawnUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getAstronomicalDuskStartDateTimeUtc, 'ExpectedAstronomicalDuskUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getNauticalDuskStartDateTimeUtc, 'ExpectedNauticalDuskUtc'), testModel(new Date(2022, 0, 1), _utcJanTwilight["default"], _index.getCivilDuskStartDateTimeUtc, 'ExpectedCivilDuskUtc')].forEach(function (testModel) {
return assertTimesAreCloseToDelta(testModel);
});
Scientific decimal time to time
returns hours.
_chai.assert.equal((0, _index.toTime)(1).hours, 1);
_chai.assert.equal((0, _index.toTime)(10).hours, 10);
_chai.assert.equal((0, _index.toTime)(100).hours, 100);
_chai.assert.equal((0, _index.toTime)(100.9).hours, 100);
_chai.assert.equal((0, _index.toTime)(10.9).hours, 10);
_chai.assert.equal((0, _index.toTime)(1.9).hours, 1);
returns minutes.
_chai.assert.equal((0, _index.toTime)(0.0166667).minutes, 1);
_chai.assert.equal((0, _index.toTime)(0.1666667).minutes, 10);
_chai.assert.equal((0, _index.toTime)(0.1666667).minutes, 10);
_chai.assert.equal((0, _index.toTime)(0.5).minutes, 30);
_chai.assert.equal((0, _index.toTime)(0.983335).minutes, 59);
returns seconds.
_chai.assert.equal((0, _index.toTime)(0.000277778).seconds, 1);
_chai.assert.equal((0, _index.toTime)(0.00277778).seconds, 10);
_chai.assert.equal((0, _index.toTime)(0.008333361).seconds, 30);
_chai.assert.equal((0, _index.toTime)(0.0138889).seconds, 50);
_chai.assert.equal((0, _index.toTime)(0.0163889).seconds, 59);
_chai.assert.equal((0, _index.toTime)(0.0166667).seconds, 0);
returns milliseconds.
_chai.assert.equal((0, _index.toTime)(0.0002775).milliseconds, 999);
_chai.assert.equal((0, _index.toTime)(0.000100278).milliseconds, 361);
_chai.assert.equal((0, _index.toTime)(0.000277778).milliseconds, 0);
_chai.assert.equal((0, _index.toTime)(0.000234167).milliseconds, 843);
returns the complete every time unit.
var decimalTime = 23.756;
var actual = (0, _index.toTime)(decimalTime);
_chai.assert.equal(actual.hours, 23);
_chai.assert.equal(actual.minutes, 45);
_chai.assert.equal(actual.seconds, 21);
_chai.assert.equal(actual.milliseconds, 600);
throws an exception when the value is null, undefined or not a number.
_chai.assert["throws"](function () {
return (0, _index.toTime)(null);
});
_chai.assert["throws"](function () {
return (0, _index.toTime)(undefined);
});
_chai.assert["throws"](function () {
return (0, _index.toTime)('One');
});
_chai.assert["throws"](function () {
return (0, _index.toTime)('');
});
Get all dates for a year
returns every distinct date for a non leap year.
var expectedYear = 2001;
var allDates = (0, _dateTestUtilities["default"])(expectedYear);
var distinctDates = allDates.map(function (s) {
return s.toString();
}).filter(function (s, i, a) {
return a.indexOf(s) === i;
}).map(function (s) {
return new Date(s);
});
var uniqueYears = _toConsumableArray(new Set(allDates.map(function (x) {
return x.getFullYear();
})));
var expectedNumberOfUniqueYears = 1;
_chai.assert.equal(allDates.length, distinctDates.length);
_chai.assert.equal(uniqueYears.length, expectedNumberOfUniqueYears);
_chai.assert.equal(uniqueYears[0], expectedYear);
returns every distinct date for a leap year.
var expectedYear = 2000;
var allDates = (0, _dateTestUtilities["default"])(expectedYear);
var distinctDates = allDates.map(function (s) {
return s.toString();
}).filter(function (s, i, a) {
return a.indexOf(s) === i;
}).map(function (s) {
return new Date(s);
});
var uniqueYears = _toConsumableArray(new Set(allDates.map(function (x) {
return x.getFullYear();
})));
var expectedNumberOfUniqueYears = 1;
_chai.assert.equal(allDates.length, distinctDates.length);
_chai.assert.equal(uniqueYears.length, expectedNumberOfUniqueYears);
_chai.assert.equal(uniqueYears[0], expectedYear);
Get day of the year
returns the correct day of the year.
_getDayOfTheYearTestData["default"].forEach(function (data) {
var date = data.date,
expectedDayOfTheYear = data.expectedDayOfTheYear;
var actualDayOfTheYearResult = (0, _index.getDayOfTheYear)(new Date(date));
_chai.assert.equal(actualDayOfTheYearResult, expectedDayOfTheYear);
});
returns day of the year for every day on a leap year.
var allDaysOnALeapYear = (0, _dateTestUtilities["default"])(1944);
allDaysOnALeapYear.forEach(function (date) {
var expectedDayOfTheYear = allDaysOnALeapYear.indexOf(date) + 1;
var actualDayOfTheYear = (0, _index.getDayOfTheYear)(date);
_chai.assert.equal(actualDayOfTheYear, expectedDayOfTheYear);
});
returns day of the year for every day on non leap year.
var allDaysOnALeapYear = (0, _dateTestUtilities["default"])(2017);
allDaysOnALeapYear.forEach(function (date) {
var expectedDayOfTheYear = allDaysOnALeapYear.indexOf(date) + 1;
var actualDayOfTheYear = (0, _index.getDayOfTheYear)(date);
_chai.assert.equal(actualDayOfTheYear, expectedDayOfTheYear);
});
throws exception when an invalid date is passed.
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)(undefined);
}, 'Please provide a valid date');
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)(null);
}, 'Please provide a valid date');
_chai.assert["throw"](function () {
return (0, _index.getDayOfTheYear)();
}, 'Please provide a valid date');
Declination of the sun
returns the correct value in degrees within +/- 0.4 degree accuracy.
_declinationOfTheSunTestData["default"].forEach(function (data) {
var date = data.date,
declination = data.declination;
var result = (0, _index["default"])(new Date(date));
var difference = result - declination;
_chai.assert.closeTo(difference, 0, 0.4);
});
throws an error if an invalid date is passed in.
var expectedErrorMessage = 'Please provide a valid date';
_chai.assert["throws"](function () {
return (0, _index["default"])(null);
}, expectedErrorMessage);
_chai.assert["throws"](function () {
return (0, _index["default"])(undefined);
}, expectedErrorMessage);
_chai.assert["throws"](function () {
return (0, _index["default"])();
}, expectedErrorMessage);
Declination Of The Sun Factory
throws an exception if you do not pass in all parameters.
var stub = function stub() {
return 1;
};
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(null, stub, stub, stub);
}, 'Please provide a function for sine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, null, stub, stub);
}, 'Please provide a function for cosine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, null, stub);
}, 'Please provide a function for arcsine.');
_chai.assert["throws"](function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, stub, null);
}, 'Please provide a function for getDayOfTheYear.');
returns a get declination of the sun function.
var stub = function stub() {
return 1;
};
_chai.assert.typeOf(function () {
return (0, _index.declinationOfTheSunFactory)(stub, stub, stub, stub).getDeclinationOfTheSun;
}, 'function');
Equation of time
returns the correct equation of time with a margin of error of +/- 4 seconds.
_equationOfTimeTestData["default"].forEach(function (expectedResult) {
var eot = expectedResult.eot,
date = expectedResult.date;
var actual = (0, _index.equationOfTime)(new Date(date));
var difference = eot * 60 - actual * 60;
_chai.assert.closeTo(difference, 0, 3.99);
});
throws an exception when an invalid date is passed in.
var expectedErrorMessage = 'Please provide a valid date';
_ch...