Skip to content

Commit

Permalink
Fix TimeOffset render
Browse files Browse the repository at this point in the history
  • Loading branch information
albiberto committed Jan 28, 2024
1 parent 6c01976 commit 9918d7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions JQLBuilder.Tests/Types/DurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void Should_Parse_Duration_m()
[TestMethod]
public void Should_Render_Literals_Correctly()
{
var expected = $"{Fields.Custom(CustomFieldId)} {Operators.Equals} {Functions.StartOfDay}(\"-1M\") {Keywords.And} " +
$"{Fields.Custom(CustomFieldId)} {Operators.Equals} {Functions.EndOfWeek}(\"1h\")";
var expected = $"{Fields.Custom(CustomFieldId)} {Operators.Equals} {Functions.StartOfDay}(-1M) {Keywords.And} " +
$"{Fields.Custom(CustomFieldId)} {Operators.Equals} {Functions.EndOfWeek}(1h)";

var actual = JqlBuilder.Query
.Where(f =>
Expand Down
27 changes: 18 additions & 9 deletions JQLBuilder/Render/Renders/JqlTypeRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,27 @@ public void Collection(IReadOnlyList<IJqlType> values)

public void TimeOffset(TimeOffset value)
{
builder.Append('"');

if (value.Years != 0) builder.Append(value.Years).Append("y ");
if (value.Months != 0) builder.Append(value.Months).Append("M ");
if (value.Weeks != 0) builder.Append(value.Weeks).Append("w ");
if (value.Days != 0) builder.Append(value.Days).Append("d ");
if (value.Hours != 0) builder.Append(value.Hours).Append("h ");
if (value.Minutes != 0) builder.Append(value.Minutes).Append("m ");
var years = value.Years != 0;
var months = value.Months != 0;
var weeks = value.Weeks != 0;
var days = value.Days != 0;
var hours = value.Hours != 0;
var minutes = value.Minutes != 0;

var complex = (years ? 1 : 0) + (months ? 1 : 0) + (weeks ? 1 : 0) + (days ? 1 : 0) + (hours ? 1 : 0) + (minutes ? 1 : 0) >= 2;

if(complex) builder.Append('"');

if (years) builder.Append(value.Years).Append("y ");
if (months) builder.Append(value.Months).Append("M ");
if (weeks) builder.Append(value.Weeks).Append("w ");
if (days) builder.Append(value.Days).Append("d ");
if (hours) builder.Append(value.Hours).Append("h ");
if (minutes) builder.Append(value.Minutes).Append("m ");

builder.Length--;

builder.Append('"');
if(complex) builder.Append('"');
}

public override string ToString() => builder.ToString();
Expand Down

0 comments on commit 9918d7e

Please sign in to comment.