Skip to content

Commit

Permalink
Merge pull request #132 from vigoren/develop
Browse files Browse the repository at this point in the history
v1.2.997
  • Loading branch information
vigoren authored Jun 16, 2021
2 parents 5dc1df5 + a8b4d5c commit 437d7e0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v1.2.97 - API Bug Fixes

- Fixed a bug with the API function timestampPlusInterval where adding just a year would increment to the first day of the year not by the number of years.
- Fixed a bug with the API function timestampPlusInterval where if very large values for the different intervals were passed in an error would be thrown

## v1.2.95 - Translations & Foundry 0.8.7

- Ensured that Simple Calendar works in foundry version 0.8.7.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "foundryvtt-simple-calendar",
"description": "A simple calendar module for keeping track of game days and events.",
"version": "1.2.95",
"version": "1.2.97",
"author": "Dean Vigoren (vigorator)",
"keywords": [
"foundryvtt",
Expand Down
6 changes: 6 additions & 0 deletions src/classes/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('API Class Tests', () => {

expect(API.timestampPlusInterval(0, {second: 86401})).toBe(86401);

expect(API.timestampPlusInterval(0, {month: 3})).toBe(7862400);
expect(API.timestampPlusInterval(0, {hour: 2184})).toBe(7862400);
expect(API.timestampPlusInterval(0, {minute: 131040})).toBe(7862400);
expect(API.timestampPlusInterval(0, {second: 7862400})).toBe(7862400);
expect(API.timestampPlusInterval(86399, {second: 1})).toBe(86400);

year.gameSystem = GameSystems.PF2E;
year.generalSettings.pf2eSync = true;
expect(API.timestampPlusInterval(0, {day: 0})).toBe(0);
Expand Down
26 changes: 24 additions & 2 deletions src/classes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Logger} from "./logging";
import {GameSettings} from "./game-settings";
import {GameSystems, TimeKeeperStatus} from "../constants";
import PF2E from "./systems/pf2e";
import Year from "./year";

/**
* All external facing functions for other systems, modules or macros to consume
Expand Down Expand Up @@ -36,13 +37,34 @@ export default class API{
const dateTime = clone.secondsToDate(currentSeconds);
clone.updateTime(dateTime);
if(interval.year){
clone.changeYear(interval.year, true, 'current');
clone.changeYear(interval.year, false, 'current');
}
if(interval.month){
//If a large number of months are passed in then
if(interval.month > clone.months.length){
let years = Math.floor(interval.month/clone.months.length);
interval.month = interval.month - (years * clone.months.length);
clone.changeYear(years, false, 'current');
}
clone.changeMonth(interval.month, 'current');
}
if(interval.day){
clone.changeDay(interval.day);
clone.changeDayBulk(interval.day);
}
if(interval.hour && interval.hour > clone.time.hoursInDay){
const days = Math.floor(interval.hour / clone.time.hoursInDay);
interval.hour = interval.hour - (days * clone.time.hoursInDay);
clone.changeDayBulk(days);
}
if(interval.minute && interval.minute > (clone.time.hoursInDay * clone.time.minutesInHour)){
const days = Math.floor(interval.minute / (clone.time.hoursInDay * clone.time.minutesInHour));
interval.minute = interval.minute - (days * (clone.time.hoursInDay * clone.time.minutesInHour));
clone.changeDayBulk(days);
}
if(interval.second && interval.second > clone.time.secondsPerDay){
const days = Math.floor(interval.second / clone.time.secondsPerDay);
interval.second = interval.second - (days * clone.time.secondsPerDay);
clone.changeDayBulk(days);
}
const dayChange = clone.time.changeTime(interval.hour, interval.minute, interval.second);
if(dayChange !== 0){
Expand Down
10 changes: 10 additions & 0 deletions src/classes/year.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ describe('Year Class Tests', () => {
expect(year.months[1].days[21].selected).toBe(false);
});

test('Change Day Bulk', () => {
year.months.push(month);
month.current = true;
month.days[0].current = true;
year.changeDayBulk(1);
expect(year.months[0].days[1].current).toBe(true);
year.changeDayBulk(31);
expect(year.numericRepresentation).toBe(1);
});

test('Change Time', () => {
year.changeTime(true, 'hour');
expect(year.time.seconds).toBe(3600);
Expand Down
17 changes: 17 additions & 0 deletions src/classes/year.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,23 @@ export default class Year {
}
}

/**
* Changes the current or selected day by the passed in amount. Adjusting for number of years first
* @param amount
* @param setting
*/
changeDayBulk(amount: number, setting: string = 'current'){
let isLeapYear = this.leapYearRule.isLeapYear(this.numericRepresentation);
let numberOfDays = this.totalNumberOfDays(isLeapYear, true);
while(amount > numberOfDays){
this.changeYear(1, false, setting);
amount -= numberOfDays;
isLeapYear = this.leapYearRule.isLeapYear(this.numericRepresentation);
numberOfDays = this.totalNumberOfDays(isLeapYear, true);
}
this.changeDay(amount, setting);
}

/**
* Changes the passed in time type by the passed in amount
* @param {boolean} next If we are going forward or backwards
Expand Down
2 changes: 1 addition & 1 deletion src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "foundryvtt-simple-calendar",
"title": "Simple Calendar",
"description": "A simple calendar module for keeping track of game days and events.",
"version": "1.2.95",
"version": "1.2.97",
"author": "Dean Vigoren (Vigorator)",
"authors": [
{
Expand Down

0 comments on commit 437d7e0

Please sign in to comment.