From 458ee0cf312b350213edf14965157eb8c3c97efb Mon Sep 17 00:00:00 2001 From: Yommy Date: Tue, 24 Mar 2020 21:32:46 +1000 Subject: [PATCH] Added support to specify the format string in UnixTimeToDate (Probably makes UnixTimeToISO8601 deprecated?) inadvertently found and fixed a bug where saving some default values is required. --- OpenBullet/LSDoc.xml | 1 + .../StackerBlocks/PageBlockFunction.xaml | 12 ++++++++++++ .../StackerBlocks/PageBlockFunction.xaml.cs | 4 ++++ RuriLib/Blocks/BlockFunction.cs | 19 +++++++++++++++++-- RuriLib/LoliScript/Writer/BlockWriter.cs | 5 +++-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/OpenBullet/LSDoc.xml b/OpenBullet/LSDoc.xml index c7c833b..3f95849 100644 --- a/OpenBullet/LSDoc.xml +++ b/OpenBullet/LSDoc.xml @@ -237,6 +237,7 @@ FUNCTION Translate StopAfterFirstMatch=True KEY "key2" VALUE "value2" "input" -> CAP "Translated" FUNCTION DateToUnixTime "format" "input" -> VAR "DATE" +FUNCTION UnixTimeToDate "format" "input" -> VAR "UNIXTIME" FUNCTION Replace "what" "with" UseRegex=True "input" -> VAR "REPLACED" FUNCTION RegexMatch "pattern" "input" -> VAR "MATCHED" FUNCTION RandomNum "0" "100" -> VAR "RANDOM" diff --git a/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml b/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml index a7401bf..d8f249a 100644 --- a/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml +++ b/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml @@ -236,6 +236,18 @@ + + + + + + diff --git a/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml.cs b/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml.cs index 4fff818..4ad2e20 100644 --- a/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml.cs +++ b/OpenBullet/Views/StackerBlocks/PageBlockFunction.xaml.cs @@ -136,6 +136,10 @@ namespace OpenBullet.Views.StackerBlocks case BlockFunction.Function.PBKDF2PKCS5: functionTabControl.SelectedIndex = 15; break; + + case BlockFunction.Function.UnixTimeToDate: + functionTabControl.SelectedIndex = 16; + break; } } diff --git a/RuriLib/Blocks/BlockFunction.cs b/RuriLib/Blocks/BlockFunction.cs index cc55a73..a9a1e19 100644 --- a/RuriLib/Blocks/BlockFunction.cs +++ b/RuriLib/Blocks/BlockFunction.cs @@ -375,6 +375,16 @@ namespace RuriLib DateFormat = LineParser.ParseLiteral(ref input, "DATE FORMAT"); break; + case Function.UnixTimeToDate: + DateFormat = LineParser.ParseLiteral(ref input, "DATE FORMAT"); + // a little backward compatability with the old line format. + if (LineParser.Lookahead(ref input) != TokenType.Literal) + { + InputString = DateFormat; + DateFormat = "yyyy-MM-dd:HH-mm-ss"; + } + break; + case Function.Replace: ReplaceWhat = LineParser.ParseLiteral(ref input, "What"); ReplaceWith = LineParser.ParseLiteral(ref input, "With"); @@ -525,7 +535,12 @@ namespace RuriLib case Function.DateToUnixTime: writer - .Literal(DateFormat, "DateFormat"); + .Literal(DateFormat, "DateFormat", true); + break; + + case Function.UnixTimeToDate: + writer + .Literal(DateFormat, "DateFormat", true); break; case Function.Replace: @@ -718,7 +733,7 @@ namespace RuriLib break; case Function.UnixTimeToDate: - outputString = double.Parse(localInputString).ToDateTime().ToShortDateString(); + outputString = double.Parse(localInputString).ToDateTime().ToString(dateFormat); break; case Function.CurrentUnixTime: diff --git a/RuriLib/LoliScript/Writer/BlockWriter.cs b/RuriLib/LoliScript/Writer/BlockWriter.cs index 4f58b21..323d4e6 100644 --- a/RuriLib/LoliScript/Writer/BlockWriter.cs +++ b/RuriLib/LoliScript/Writer/BlockWriter.cs @@ -63,10 +63,11 @@ namespace RuriLib.LS /// /// The literal value to write /// The name of the property of the block. If the value is the default one, it will not be written. Do not set this parameter to always write the variable. + /// Always write the value even if that value is default /// The BlockWriter itself - public BlockWriter Literal(string literal, string property = "") + public BlockWriter Literal(string literal, string property = "", bool alwaysWrite = false) { - if (property != string.Empty && CheckDefault(literal, property)) return this; + if (property != string.Empty && (!alwaysWrite && CheckDefault(literal, property))) return this; Write($"\"{literal.Replace("\\", "\\\\").Replace("\"", "\\\"")}\" "); return this; }