diff --git a/.gitignore b/.gitignore
index 25627a9..bbaed47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ bld/
[Oo]bj/
[Ll]og/
*.dll
+!Distribution/Release/GameData/Kronometer/Plugins/Kronometer.dll
# Visual Studio 2015 cache/options directory
.vs/
diff --git a/Distribution/Release/Changelog.txt b/Distribution/Release/Changelog.txt
index eefbe79..3bc9aa1 100644
--- a/Distribution/Release/Changelog.txt
+++ b/Distribution/Release/Changelog.txt
@@ -1,3 +1,9 @@
+v1.3.0-2
+
+- Fixed an issue in date calculation for non leap dates
+- Added a bool to force values of time units to be integers
+
+
v1.3.0-1
- First Release
\ No newline at end of file
diff --git a/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.dll b/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.dll
new file mode 100644
index 0000000..d3241ca
Binary files /dev/null and b/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.dll differ
diff --git a/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.version b/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.version
index ec74c39..59e5324 100644
--- a/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.version
+++ b/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.version
@@ -1,5 +1,5 @@
{
- "NAME": "Kronometer",
+ "NAME": "Kronometer",
"URL": "https://raw.githubusercontent.com/StollD/Kronometer/master/Distribution/Release/GameData/Kronometer/Plugins/Kronometer.version",
"DOWNLOAD": "https://github.com/StollD/Kronometer/releases/latest",
"CHANGE_LOG_URL": "https://raw.githubusercontent.com/StollD/Kronometer/master/Distribution/Release/Changelog.txt",
@@ -14,7 +14,7 @@
"MAJOR": 1,
"MINOR": 3,
"PATCH": 0,
- "BUILD": 1
+ "BUILD": 2
},
"KSP_VERSION":
{
diff --git a/README.md b/README.md
index 4f89436..e1e68f9 100644
--- a/README.md
+++ b/README.md
@@ -106,6 +106,7 @@ The Kronometer root node contains five general settings and three nodes for more
- **plural**, *\*, which is the plural name of the time unit (eg. *'Years'*)
- **symbol**, *\*, which is the symbol used for the time unit (eg. *'y'*)
- **value**, *\*, which is the duration in 'real life seconds' of the time unit (eg. *'9201600'*)
+ - **roundToNearestInt**, *\*, which (if true) makes sure the 'value' is an integer number
---
diff --git a/src/Kronometer.cs b/src/Kronometer.cs
index 7874325..e1915e3 100644
--- a/src/Kronometer.cs
+++ b/src/Kronometer.cs
@@ -55,14 +55,29 @@ void Start()
loader.Clock.year.value = Math.Abs(loader.Clock.year.value);
loader.Clock.day.value = Math.Abs(loader.Clock.day.value);
- // If weird numbers, abort
- if (double.IsInfinity(loader.Clock.day.value) || double.IsNaN(loader.Clock.day.value) || double.IsInfinity(loader.Clock.year.value) || double.IsNaN(loader.Clock.year.value))
+ // Round values where it is required
+ if (loader.Clock.year.round)
+ loader.Clock.year.value = Math.Round(loader.Clock.year.value, 0);
+ if (loader.Clock.day.round)
+ loader.Clock.day.value = Math.Round(loader.Clock.day.value, 0);
+ if (loader.Clock.hour.round)
+ loader.Clock.hour.value = Math.Round(loader.Clock.hour.value, 0);
+ if (loader.Clock.minute.round)
+ loader.Clock.minute.value = Math.Round(loader.Clock.minute.value, 0);
+ if (loader.Clock.second.round)
+ loader.Clock.second.value = Math.Round(loader.Clock.second.value, 0);
+
+ if // Make sure we still need the clock and all values are still defined properly
+ (
+ double.PositiveInfinity > loader.Clock.hour.value &&
+ loader.Clock.hour.value > loader.Clock.minute.value &&
+ loader.Clock.minute.value > loader.Clock.second.value &&
+ loader.Clock.second.value > 0
+ )
{
- return;
+ // Replace the stock Formatter
+ KSPUtil.dateTimeFormatter = new ClockFormatter(loader);
}
-
- // Replace the stock Formatter
- KSPUtil.dateTimeFormatter = new ClockFormatter(loader);
}
}
}
@@ -389,14 +404,20 @@ public virtual Date GetDate(double time)
// Time passed this year
double timeThisYear = time - loader.Clock.year.value * year;
+ // Time carried over each year
+ double AnnualCarryOver = loader.Clock.year.value % loader.Clock.day.value;
+
+ // Time carried over to this day
+ double TotalCarryOver = AnnualCarryOver * year;
+
// Time carried over from last year
- double CarryOver = CarryOver = loader.Clock.day.value - Math.Abs((loader.Clock.year.value % loader.Clock.day.value) * year);
+ double CarryOver = MOD(TotalCarryOver, loader.Clock.day.value);
// Current Day of the year
int day = (int)Math.Floor((timeThisYear - CarryOver) / loader.Clock.day.value.value);
// Time left to count
- double left = (time % loader.Clock.day.value + loader.Clock.day.value) % loader.Clock.day.value;
+ double left = MOD(time, loader.Clock.day.value);
// Number of hours in this day
int hours = (int)(left / loader.Clock.hour.value);
@@ -473,7 +494,7 @@ public virtual Date GetLeapDate(double time)
// Now 'day' and 'year' correctly account for leap years
// Time left to count
- double left = (time % loader.Clock.day.value + loader.Clock.day.value) % loader.Clock.day.value;
+ double left = MOD(time, loader.Clock.day.value);
// Number of hours in this day
int hours = (int)(left / loader.Clock.hour.value);
@@ -508,7 +529,7 @@ public virtual Date GetLeapDate(double time)
int daysBetweenResets = (daysInOneShortYear * loader.resetMonths) + (int)(chanceOfLeapDay * loader.resetMonths);
// Days passed since last month reset
- int daysFromReset = (daysPassedTOT % daysBetweenResets + daysBetweenResets) % daysBetweenResets;
+ int daysFromReset = (int)MOD(daysPassedTOT, daysBetweenResets);
@@ -811,6 +832,19 @@ private static string CheckNum(double time)
return null;
}
+ ///
+ /// Returns the remainder after number is divided by divisor. The result has the same sign as divisor.
+ ///
+ /// The number for which you want to find the remainder.
+ /// The number by which you want to divide number.
+ ///
+ public double MOD(double number, double divisor)
+ {
+ return (number % divisor + divisor) % divisor;
+ }
+
+ /// In these Properties is stored the length of each time unit in game seconds
+ /// These can be found in stock as well, and should be used by other mods that deal with time
public virtual int Second
{
get { return (int)loader.Clock.second.value; }
diff --git a/src/KronometerLoader.cs b/src/KronometerLoader.cs
index ce44051..da6642c 100644
--- a/src/KronometerLoader.cs
+++ b/src/KronometerLoader.cs
@@ -112,12 +112,16 @@ public class TimeUnits
[ParserTarget("value")]
public NumericParser value;
- public TimeUnits(string singular, string plural, string symbol, double value)
+ [ParserTarget("roundToNearestInt")]
+ public NumericParser round;
+
+ public TimeUnits(string singular, string plural, string symbol, double value, bool round = false)
{
this.singular = singular;
this.plural = plural;
this.symbol = symbol;
- this.value = value;
+ this.value = round ? Math.Round(value, 0) : value;
+ this.round = round;
}
}