Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiled against 1.4.3 and restructured some files #9

Merged
merged 1 commit into from
May 29, 2018
Merged
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
81 changes: 41 additions & 40 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#Autosave files
*~

#build
[Oo]bj/
[Bb]in/
packages/
TestResults/

# globs
Makefile.in
*.DS_Store
*.sln.cache
*.suo
*.cache
*.pidb
*.userprefs
*.usertasks
config.log
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.user
*.tar.gz
tarballs/
test-results/
Thumbs.db

#Mac bundle stuff
*.dmg
*.app

#resharper
*_Resharper.*
*.Resharper

#dotCover
*.dotCover
#Autosave files
*~

#build
[Oo]bj/
[Bb]in/
packages/
TestResults/

# globs
Makefile.in
*.DS_Store
*.sln.cache
*.suo
*.cache
*.pidb
*.userprefs
*.usertasks
config.log
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.user
*.tar.gz
tarballs/
test-results/
Thumbs.db

#Mac bundle stuff
*.dmg
*.app

#resharper
*_Resharper.*
*.Resharper

#dotCover
*.dotCover
*.zip
Binary file modified GameData/RSSDateTime/Plugins/RSSTimeFormatter.dll
100755 → 100644
Binary file not shown.
65 changes: 65 additions & 0 deletions RSSTimeFormatter/DTReplacer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using UnityEngine;

namespace RSSTimeFormatter
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class DTReplacer : MonoBehaviour
{
public static string GetUniqueStringFromUniqueNode(string name, string node)
{
var configs = GameDatabase.Instance.GetConfigs(node);
if (configs.Length > 1) {
Debug.LogError(
"Multiple `" + node + "` configurations, falling back to default");
}
else if (configs.Length == 1) {
ConfigNode config = configs[0].config;
var formats = config.GetValues(name);
if (formats.Length > 1) {
Debug.LogError(
"`" + node + "` configuration has multiple `" + name + "` entries, falling back to default");
}
else if (formats.Length == 1) {
return formats[0];
}
}
return null;
}

public void Start()
{
Debug.Log("Replacing DateTime formatter");
// Since Unity overrides the CurrentCulture, we cannot rely on it to
// format dates in a way that the user will understand, see
// https://github.com/KSP-RO/RSSTimeFormatter/issues/2.
// This default is an international standard, namely ISO 8601 extended
// format. It is chosen (and was designed) to avoid ambiguities on the
// order of month and day that are inevitable with formats using
// slashes.
string dateFormat = "yyyy-MM-dd";
string customDateFormat = GetUniqueStringFromUniqueNode("dateFormat", "RSSTimeFormatter");
if (customDateFormat != null) {
// Validate the format string.
try {
string.Format("{0:" + customDateFormat + "}", new DateTime(1957, 10, 04));
dateFormat = customDateFormat;
}
catch (FormatException) {
Debug.LogError("Invalid date format " + customDateFormat);
}
}

DateTime epoch = new DateTime(1951, 01, 01);
string customEpoch = GetUniqueStringFromUniqueNode("epoch", "RSSTimeFormatter");
if (customEpoch != null) {
if (!DateTime.TryParse(customEpoch, out epoch)) {
Debug.LogError("Invalid epoch " + customEpoch);
}
}

KSPUtil.dateTimeFormatter = new RealDateTimeFormatter(dateFormat, epoch);
}
}
}

Loading