Skip to content

Commit

Permalink
0.8.0 - rename DateTimes -> index, add npm script 'build-package' for…
Browse files Browse the repository at this point in the history
… new release tarball.
  • Loading branch information
TeamworkGuy2 committed Apr 9, 2018
1 parent a7e8892 commit 16e3a06
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
### [0.7.5](N/A) - 2018-03-31
### [0.7.6](N/A) - 2018-04-09
#### Changed
* Added release tarball and npm script `build-package` to package.json referencing external process to generate tarball


--------
### [0.7.5](https://github.com/TeamworkGuy2/ts-date-times/commit/a7e889245dd0f11a3cab821f8df9d100a73d0944) - 2018-03-31
#### Changed
* Update to TypeScript 2.8
* Update tsconfig.json with `noImplicitReturns: true` and `forceConsistentCasingInFileNames: true`
Expand Down
18 changes: 9 additions & 9 deletions DateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var DateConstants = require("./DateConstants");
var DateUtil;
(function (DateUtil) {
DateUtil.DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK = 1;
DateUtil.DEFAULT_MIN_DAYS_IN_FIRST_WEEK = 1;
/** Create a midnight (00:00) date for the given year, month, date using the Date constructor
*/
function newMidnightDate(year, month, day) {
Expand Down Expand Up @@ -41,33 +41,33 @@ var DateUtil;
return 1 + Math.floor(getMillisSince(date, startOfYear) / DateConstants.MILLIS_PER_DAY);
}
DateUtil.getDayInYear = getDayInYear;
function getWeekInMonth(date, minimalDaysInFirstWeek) {
if (minimalDaysInFirstWeek == null) {
minimalDaysInFirstWeek = DateUtil.DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK;
function getWeekInMonth(date, minDaysInFirstWeek) {
if (minDaysInFirstWeek == null) {
minDaysInFirstWeek = DateUtil.DEFAULT_MIN_DAYS_IN_FIRST_WEEK;
}
var previousSunday = getPreviousSunday(date);
var startOfMonth = newMidnightDate(date.getFullYear(), date.getMonth(), 1);
var numberOfSundays = isBefore(previousSunday, startOfMonth) ?
0 : 1 + Math.floor(getMillisSince(previousSunday, startOfMonth) / DateConstants.MILLIS_PER_WEEK);
var numberOfDaysInFirstWeek = 7 - startOfMonth.getDay();
var weekInMonth = numberOfSundays;
if (numberOfDaysInFirstWeek >= minimalDaysInFirstWeek) {
if (numberOfDaysInFirstWeek >= minDaysInFirstWeek) {
weekInMonth++;
}
return weekInMonth;
}
DateUtil.getWeekInMonth = getWeekInMonth;
function getWeekInYear(date, minimalDaysInFirstWeek) {
if (minimalDaysInFirstWeek == null) {
minimalDaysInFirstWeek = DateUtil.DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK;
function getWeekInYear(date, minDaysInFirstWeek) {
if (minDaysInFirstWeek == null) {
minDaysInFirstWeek = DateUtil.DEFAULT_MIN_DAYS_IN_FIRST_WEEK;
}
var previousSunday = getPreviousSunday(date);
var startOfYear = newMidnightDate(date.getFullYear(), 0, 1);
var weeksSinceSartOfYear = Math.floor(getMillisSince(previousSunday, startOfYear) / DateConstants.MILLIS_PER_WEEK);
var numberOfSundays = isBefore(previousSunday, startOfYear) ? 0 : 1 + weeksSinceSartOfYear;
var numberOfDaysInFirstWeek = 7 - startOfYear.getDay();
var weekInYear = numberOfSundays;
if (numberOfDaysInFirstWeek < minimalDaysInFirstWeek) {
if (numberOfDaysInFirstWeek < minDaysInFirstWeek) {
weekInYear--;
}
return weekInYear;
Expand Down
18 changes: 9 additions & 9 deletions DateUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DateConstants = require("./DateConstants");

module DateUtil {
export var DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK = 1;
export var DEFAULT_MIN_DAYS_IN_FIRST_WEEK = 1;


/** Create a midnight (00:00) date for the given year, month, date using the Date constructor
Expand Down Expand Up @@ -48,34 +48,34 @@ module DateUtil {
}


export function getWeekInMonth(date: Date, minimalDaysInFirstWeek?: number | null | undefined): number {
if (minimalDaysInFirstWeek == null) {
minimalDaysInFirstWeek = DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK;
export function getWeekInMonth(date: Date, minDaysInFirstWeek?: number | null | undefined): number {
if (minDaysInFirstWeek == null) {
minDaysInFirstWeek = DEFAULT_MIN_DAYS_IN_FIRST_WEEK;
}
var previousSunday = getPreviousSunday(date);
var startOfMonth = newMidnightDate(date.getFullYear(), date.getMonth(), 1);
var numberOfSundays = isBefore(previousSunday, startOfMonth) ?
0 : 1 + Math.floor(getMillisSince(previousSunday, startOfMonth) / DateConstants.MILLIS_PER_WEEK);
var numberOfDaysInFirstWeek = 7 - startOfMonth.getDay();
var weekInMonth = numberOfSundays;
if (numberOfDaysInFirstWeek >= minimalDaysInFirstWeek) {
if (numberOfDaysInFirstWeek >= minDaysInFirstWeek) {
weekInMonth++;
}
return weekInMonth;
}


export function getWeekInYear(date: Date, minimalDaysInFirstWeek?: number | null | undefined): number {
if (minimalDaysInFirstWeek == null) {
minimalDaysInFirstWeek = DEFAULT_MINIMAL_DAYS_IN_FIRST_WEEK;
export function getWeekInYear(date: Date, minDaysInFirstWeek?: number | null | undefined): number {
if (minDaysInFirstWeek == null) {
minDaysInFirstWeek = DEFAULT_MIN_DAYS_IN_FIRST_WEEK;
}
var previousSunday = getPreviousSunday(date);
var startOfYear = newMidnightDate(date.getFullYear(), 0, 1);
var weeksSinceSartOfYear = Math.floor(getMillisSince(previousSunday, startOfYear) / DateConstants.MILLIS_PER_WEEK);
var numberOfSundays = isBefore(previousSunday, startOfYear) ? 0 : 1 + weeksSinceSartOfYear;
var numberOfDaysInFirstWeek = 7 - startOfYear.getDay();
var weekInYear = numberOfSundays;
if (numberOfDaysInFirstWeek < minimalDaysInFirstWeek) {
if (numberOfDaysInFirstWeek < minDaysInFirstWeek) {
weekInYear--;
}
return weekInYear;
Expand Down
1 change: 1 addition & 0 deletions DateTimes.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var ts = Timestamps;
/** DateTimes - contains static sub-modules for date and time operations, including:
* - DateConstants: for date constants such as the days of the week or milliseconds in a day
* - Dates: for working with JS 'Date' objects and converting to display strings
* - DateUtil: for day-of-week lookup, isBefore(), isSameDate(), etc.
* - Timestamps: working with UTC millisecond Unix epoch offsets
* - DotNetJsonDate: for working with .NET JSON serialized date-time strings
*/
Expand Down
1 change: 1 addition & 0 deletions DateTimes.ts → index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var ts = Timestamps;
/** DateTimes - contains static sub-modules for date and time operations, including:
* - DateConstants: for date constants such as the days of the week or milliseconds in a day
* - Dates: for working with JS 'Date' objects and converting to display strings
* - DateUtil: for day-of-week lookup, isBefore(), isSameDate(), etc.
* - Timestamps: working with UTC millisecond Unix epoch offsets
* - DotNetJsonDate: for working with .NET JSON serialized date-time strings
*/
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"name": "ts-date-times",
"version": "0.7.5",
"version": "0.7.6",
"description": "Manage dates, timestamps, and .NET DateTime JSON in TypeScript",
"author": "TeamworkGuy2",
"homepage": "https://github.com/TeamworkGuy2/ts-date-times",
"license": "MIT",
"main": "index.js",
"dependencies": {
},
"devDependencies": {
"@types/chai": "~4.1.2",
"@types/mocha": "~5.0.0",
"chai": "~4.1.2",
"mocha": "~5.0.5",
"package-tarball": "~0.1.0",
"typescript": "~2.8.0"
},
"scripts": {
"build-package": "node ../package-tarball/index.js",
"test": "mocha -u tdd --recursive",
"tsc": "tsc"
}
Expand Down
2 changes: 1 addition & 1 deletion test/DateTimesTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var chai = require("chai");
var DateTimes = require("../DateTimes");
var DateTimes = require("../index");
var DateConstants = DateTimes.DateConstants, Dates = DateTimes.Dates, DateUtil = DateTimes.DateUtil, Timestamps = DateTimes.Timestamps, DotNetJsonDate = DateTimes.DotNetJsonDate;
var asr = chai.assert;
suite("DateTimes", function DateTimesTest() {
Expand Down
2 changes: 1 addition & 1 deletion test/DateTimesTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chai = require("chai");
import mocha = require("mocha");
import DateTimes = require("../DateTimes");
import DateTimes = require("../index");

var { DateConstants, Dates, DateUtil, Timestamps, DotNetJsonDate } = DateTimes;

Expand Down

0 comments on commit 16e3a06

Please sign in to comment.