Skip to content

Commit

Permalink
Sum timespans
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Dec 14, 2024
1 parent cd7f97c commit a607acd
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 25 deletions.
3 changes: 2 additions & 1 deletion OneMore/Commands/Tables/FormulaDialog.Designer.cs

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

11 changes: 10 additions & 1 deletion OneMore/Commands/Tables/FormulaDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ private void ChangedFormula(object sender, EventArgs e)
var result = calculator.Compute(formula);
validStatusLabel.ForeColor = manager.GetColor("ControlText");

validStatusLabel.Text = $"{Resx.word_OK} ({result})";
var text = Format == FormulaFormat.Time
? TimeSpan.FromMilliseconds(result).ToString()
: $"{result}";

validStatusLabel.Text = $"{Resx.word_OK} ({text})";
tooltip.SetToolTip(validStatusLabel, string.Empty);

okButton.Enabled = true;
Expand Down Expand Up @@ -152,6 +156,11 @@ private void GetCellValue(object sender, GetCellValueEventArgs e)
.Replace(AddIn.Culture.NumberFormat.CurrencySymbol, string.Empty)
.Replace(AddIn.Culture.NumberFormat.PercentSymbol, string.Empty);

if (TimeSpan.TryParse(e.Value, AddIn.Culture, out var tvalue))
{
e.Value = tvalue.TotalMilliseconds.ToString();
}

logger.Verbose($"FormulaDialog.GetCellValue({e.Name}) = [{e.Value}]");
}

Expand Down
6 changes: 3 additions & 3 deletions OneMore/Commands/Tables/FormulaDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ Cell reference: A1, A2, ... ZZZ999
Cell range: A1:A22
Relative ranges: A1:cell(0,-1)</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="tooltip.TrayLocation" type="System.Drawing.Point, System.Drawing">
<metadata name="tooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</data>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABABIAICAAAAEACACoCAAAJgEAABAQAAABAAgAaAUAAM4JAABAQAAAAQAIACgWAAA2DwAAMDAAAAEA
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Commands/Tables/Formulas/FormulaEnums.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//************************************************************************************************
// Copyright © 2020 Steven M Cohn. All rights reserved.
// Copyright © 2020 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands.Tables.Formulas
Expand All @@ -9,7 +9,8 @@ internal enum FormulaFormat
{
Number,
Currency,
Percentage
Percentage,
Time
}


Expand Down
13 changes: 13 additions & 0 deletions OneMore/Commands/Tables/Formulas/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ private void GetCellValue(object sender, GetCellValueEventArgs e)
return;
}

if (TimeSpan.TryParse(text, AddIn.Culture, out var tvalue))
{
// timespans are returned as milliseconds, to be converted
// back to formatted strings by the Report() method
e.Value = tvalue.TotalMilliseconds.ToString();
return;
}

// has a todo checkbox? If so then the comparison is limited to the checkbox
// and WILL NOT fall thru to a string comparison!
var tagx = cell.Root.Descendants().FirstOrDefault(d => d.Name.LocalName == "Tag");
Expand Down Expand Up @@ -146,6 +154,11 @@ private void Report(TableCell cell, Formula formula, double result)
case FormulaFormat.Percentage:
text = (result / 100).ToString($"P{dplaces}", AddIn.Culture);
break;

case FormulaFormat.Time:
var span = TimeSpan.FromMilliseconds(result);
text = span.ToString();
break;
}

cell.SetContent(text);
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.Designer.cs

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

3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>رقم
عملة
النسبة المئوية</value>
نسبة مئوية
وقت</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
5 changes: 4 additions & 1 deletion OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,10 @@ OneNote-Datei (*.one)</value>
<comment>label</comment>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Nummer\n</value>
<value>Nummer
Währung
Prozentsatz
Zeit</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,9 @@ Archivo de OneNote (* .one)</value>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Número
Moneda
Porcentaje</value>
Divisa
Porcentaje
Tiempo</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ Fichier OneNote (*.one)</value>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Nombre
Devise
Pourcentage</value>
Pourcentage
Temps</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Properties/Resources.he-IL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,10 @@ Total Row Font
<comment>label</comment>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>מספר
<value>מִספָּר
מַטְבֵּעַ
אֲחוּזִים</value>
אֲחוּזִים
זְמַן</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,10 @@ OneNoteファイル (*.one)</value>
<comment>label</comment>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>数値
<value>番号
通貨
パーセンテージ</value>
パーセンテージ
時間</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
7 changes: 4 additions & 3 deletions OneMore/Properties/Resources.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,10 @@ OneNote-bestand (*.one)</value>
<comment>label</comment>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Aantal
Valuta
Percentage</value>
<value>Nummer
Munteenheid
Percentage
Tijd</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ Plik OneNote (* .o)</value>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Numer
Waluta
Odsetek</value>
Procent
Czas</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ Arquivo OneNote (* .one)</value>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Número
Moeda
Percentagem</value>
Percentagem
Tempo</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ OneNote File (*.one)</value>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>Number
Currency
Percentage</value>
Percentage
Time</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,10 @@ OneNote 文件 (*.one)</value>
<comment>label</comment>
</data>
<data name="FormulaDialog_formatBox.Items" xml:space="preserve">
<value>
<value>数字
货币
百分比</value>
百分比
时间</value>
<comment>formats, one per line</comment>
</data>
<data name="FormulaDialog_formatLabel.Text" xml:space="preserve">
Expand Down

0 comments on commit a607acd

Please sign in to comment.