Skip to content

Commit

Permalink
! Added seconds since mid-night option to auto version changer (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jan 21, 2022
1 parent ec51614 commit 25b6ab5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Codist/AutoBuildVersion/VersionRewriteMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum VersionRewriteMode
DayOfYear,
Hour,
HourMinute,
DaySinceY2K
DaySinceY2K,
MidNightSecond
}
}
11 changes: 9 additions & 2 deletions Codist/AutoBuildVersion/VersionSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Codist.AutoBuildVersion
{
public sealed class VersionSetting
{
const int MaxVersionNumber = 65535;

static readonly IFormatProvider __Format = System.Globalization.CultureInfo.InvariantCulture;
public VersionRewriteMode Major { get; set; }
public VersionRewriteMode Minor { get; set; }
Expand All @@ -27,7 +29,7 @@ public string Rewrite(string major, string minor, string build, string revision)

string WritePart(string part, VersionRewriteMode mode) {
switch (mode) {
case VersionRewriteMode.Increment: return Int32.TryParse(part, System.Globalization.NumberStyles.Integer, __Format, out var n) ? (++n).ToText() : part;
case VersionRewriteMode.Increment: return Int32.TryParse(part, System.Globalization.NumberStyles.Integer, __Format, out var n) ? NormalizeNumber(++n) : part;
case VersionRewriteMode.Zero: return "0";
case VersionRewriteMode.Year: return DateTime.Now.Year.ToText();
case VersionRewriteMode.Month: return DateTime.Now.Month.ToText();
Expand All @@ -38,13 +40,18 @@ string WritePart(string part, VersionRewriteMode mode) {
case VersionRewriteMode.DayOfYear: return DateTime.Now.DayOfYear.ToText();
case VersionRewriteMode.Hour: return DateTime.Now.Hour.ToText();
case VersionRewriteMode.HourMinute: return DateTime.Now.Hour.ToText() + DateTime.Now.Minute.ToString("00", __Format);
case VersionRewriteMode.DaySinceY2K: return ((int)(DateTime.Now.Date - new DateTime(2000, 1, 1)).TotalDays).ToText();
case VersionRewriteMode.DaySinceY2K: return NormalizeNumber((int)(DateTime.Now.Date - new DateTime(2000, 1, 1)).TotalDays);
case VersionRewriteMode.MidNightSecond: return ((int)((DateTime.Now - DateTime.Today).TotalSeconds / 2)).ToText();
default: return part;
}
}

public override string ToString() {
return $"{Major}.{Minor}.{Build}.{Revision}";
}

static string NormalizeNumber(int n) {
return (n > MaxVersionNumber ? MaxVersionNumber : n < 0 ? 0 : n).ToText();
}
}
}
2 changes: 1 addition & 1 deletion Codist/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Codist/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ Right click: Wrap text menu...</value>
<value>Configuration:</value>
</data>
<data name="T_VersionRewriteMode" xml:space="preserve">
<value>Unchanged/Increment/Zero/Year/Month/Date/ShortYear/YearMonth/MonthDate/DayOfYear/Hour/HourMinute/DaySinceY2K</value>
<value>Unchanged/Increment/Zero/Year/Month/Date/ShortYear/YearMonth/MonthDate/DayOfYear/Hour/HourMinute/DaySinceY2K/MidNightSecond</value>
</data>
<data name="CMD_SaveBuildSetting" xml:space="preserve">
<value>Save</value>
Expand Down
2 changes: 1 addition & 1 deletion Codist/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ ALL existing items will be REPLACE by default items.</value>
<value>Configuration:</value>
</data>
<data name="T_VersionRewriteMode" xml:space="preserve">
<value>Unchanged/Increment/Zero/Year/Month/Date/ShortYear/YearMonth/MonthDate/DayOfYear/Hour/HourMinute/DaySinceY2K</value>
<value>Unchanged/Increment/Zero/Year/Month/Date/ShortYear/YearMonth/MonthDate/DayOfYear/Hour/HourMinute/DaySinceY2K/MidNightSecond</value>
</data>
<data name="CMD_SaveBuildSetting" xml:space="preserve">
<value>Save</value>
Expand Down
2 changes: 1 addition & 1 deletion Codist/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ Ctrl+1, Ctrl+3: Edit.SearchDeclarationInProject</value>
<value>生成项目的配置:</value>
</data>
<data name="T_VersionRewriteMode" xml:space="preserve">
<value>不变/加1/置0/年yyyy/月m/日d/年yy/年月yymm/月日mdd/年日ddd/时h/时分hmm/2000年起日</value>
<value>不变/加1/置0/年yyyy/月m/日d/年yy/年月yymm/月日mdd/年日ddd/时h/时分hmm/2000年起日/午夜起双秒</value>
</data>
<data name="CMD_SaveBuildSetting" xml:space="preserve">
<value>保存</value>
Expand Down

0 comments on commit 25b6ab5

Please sign in to comment.