Skip to content

Commit 9e61beb

Browse files
committed
Updating
1 parent 8b085c4 commit 9e61beb

File tree

7 files changed

+44
-42
lines changed

7 files changed

+44
-42
lines changed

AzureDevopsStateTracker/Adapters/WorkItemAdapter.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using AzureDevopsStateTracker.DTOs;
22
using AzureDevopsStateTracker.Entities;
33
using AzureDevopsStateTracker.Interfaces;
4-
using System;
54
using System.Collections.Generic;
65
using System.Linq;
76

@@ -87,8 +86,8 @@ public TimeByStateDTO ToTimeByStateDTO(TimeByState workItemStatusTime)
8786
{
8887
CreatedAt = workItemStatusTime.CreatedAt,
8988
State = workItemStatusTime.State,
90-
TotalTime = ToStringTime(new DateTime(workItemStatusTime.TotalTime).TimeOfDay),
91-
TotalWorkedTime = ToStringTime(new DateTime(workItemStatusTime.TotalWorkedTime).TimeOfDay)
89+
TotalTime = workItemStatusTime.TotalTimeText,
90+
TotalWorkedTime = workItemStatusTime.TotalWorkedTimeText
9291
};
9392
}
9493

@@ -106,22 +105,5 @@ public List<TimeByStateDTO> ToTimeByStatesDTO(List<TimeByState> workItemStatusTi
106105
.Where(w => w != null)
107106
.ToList();
108107
}
109-
110-
public string ToStringTime(TimeSpan timeSpan)
111-
{
112-
if (timeSpan.Days > 0)
113-
return $@"{timeSpan:%d} Dia(s) {timeSpan:%h}h e {timeSpan:%m}min e {timeSpan:%s}s";
114-
115-
if (timeSpan.Hours > 0)
116-
return $@"{timeSpan:%h}h e {timeSpan:%m}min e {timeSpan:%s}s";
117-
118-
if (timeSpan.Minutes > 0)
119-
return $@"{timeSpan:%m}min e {timeSpan:%s}s";
120-
121-
if (timeSpan.Seconds > 0)
122-
return $@"{timeSpan:%s}s";
123-
124-
return $@"{timeSpan:%hh}:{timeSpan:%mm}:{timeSpan:%ss}";
125-
}
126108
}
127109
}

AzureDevopsStateTracker/Entities/TimeByState.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ public class TimeByState : Entity
88
public string WorkItemId { get; private set; }
99
public string State { get; private set; }
1010
public long TotalTime { get; private set; }
11+
public string TotalTimeText { get; private set; }
1112
public long TotalWorkedTime { get; private set; }
13+
public string TotalWorkedTimeText { get; private set; }
14+
1215
public WorkItem WorkItem { get; private set; }
1316

1417
private TimeByState() { }
1518

16-
public TimeByState(string workItemId, string state, long totalTime, long totalWorkedTime)
19+
public TimeByState(string workItemId, string state, TimeSpan totalTime, TimeSpan totalWorkedTime)
1720
{
1821
WorkItemId = workItemId;
1922
State = state;
20-
TotalTime = totalTime;
21-
TotalWorkedTime = totalWorkedTime;
23+
TotalTime = totalTime.Ticks;
24+
TotalTimeText = totalTime.ToTextTime();
25+
TotalWorkedTime = totalWorkedTime.Ticks;
26+
TotalWorkedTimeText = totalWorkedTime.ToTextTime();
2227

2328
Validate();
2429
}

AzureDevopsStateTracker/Entities/WorkItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public IEnumerable<TimeByState> CalculateTotalTimeByState()
119119
totalWorkedTime += data.CalculateTotalWorkedTime();
120120
}
121121

122-
timesByStateList.Add(new TimeByState(Id, workItemChange.Key, totalTime.Ticks, totalWorkedTime.Ticks));
122+
timesByStateList.Add(new TimeByState(Id, workItemChange.Key, totalTime, totalWorkedTime));
123123
}
124124

125125
return timesByStateList;
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
5-
using System.Text.RegularExpressions;
63

74
namespace AzureDevopsStateTracker.Extensions
85
{
@@ -13,19 +10,6 @@ public static bool IsNullOrEmpty(this string text)
1310
return string.IsNullOrEmpty(text?.Trim());
1411
}
1512

16-
/// <summary>
17-
/// Calculates the sum of the given timeSpans.
18-
/// </summary>
19-
public static TimeSpan Sum(this IEnumerable<TimeSpan> timeSpans)
20-
{
21-
TimeSpan sumTillNowTimeSpan = TimeSpan.Zero;
22-
23-
foreach (TimeSpan timeSpan in timeSpans)
24-
sumTillNowTimeSpan += timeSpan;
25-
26-
return sumTillNowTimeSpan;
27-
}
28-
2913
public static string ExtractEmail(this string user)
3014
{
3115
if (user is null)
@@ -36,5 +20,22 @@ public static string ExtractEmail(this string user)
3620

3721
return user.Split("<").LastOrDefault().Split(">").FirstOrDefault();
3822
}
23+
24+
public static string ToTextTime(this TimeSpan timeSpan)
25+
{
26+
if (timeSpan.Days > 0)
27+
return $@"{timeSpan:%d} Dia(s) {timeSpan:%h} h e {timeSpan:%m} min e {timeSpan:%s} s";
28+
29+
if (timeSpan.Hours > 0)
30+
return $@"{timeSpan:%h} h e {timeSpan:%m} min e {timeSpan:%s} s";
31+
32+
if (timeSpan.Minutes > 0)
33+
return $@"{timeSpan:%m} min e {timeSpan:%s} s";
34+
35+
if (timeSpan.Seconds > 0)
36+
return $@"{timeSpan:%s} s";
37+
38+
return "-";
39+
}
3940
}
4041
}

AzureDevopsStateTracker/Migrations/20210717144104_AzureDevopsStateTrackerInitial.Designer.cs renamed to AzureDevopsStateTracker/Migrations/20210718145727_AzureDevopsStateTrackerInitial.Designer.cs

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AzureDevopsStateTracker/Migrations/20210717144104_AzureDevopsStateTrackerInitial.cs renamed to AzureDevopsStateTracker/Migrations/20210718145727_AzureDevopsStateTrackerInitial.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
4747
WorkItemId = table.Column<string>(type: "varchar(200)", nullable: true),
4848
State = table.Column<string>(type: "varchar(200)", nullable: true),
4949
TotalTime = table.Column<long>(nullable: false),
50-
TotalWorkedTime = table.Column<long>(nullable: false)
50+
TotalTimeText = table.Column<string>(type: "varchar(200)", nullable: true),
51+
TotalWorkedTime = table.Column<long>(nullable: false),
52+
TotalWorkedTimeText = table.Column<string>(type: "varchar(200)", nullable: true)
5153
},
5254
constraints: table =>
5355
{

AzureDevopsStateTracker/Migrations/AzureDevopsStateTrackerContextModelSnapshot.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ protected override void BuildModel(ModelBuilder modelBuilder)
3535
b.Property<long>("TotalTime")
3636
.HasColumnType("bigint");
3737

38+
b.Property<string>("TotalTimeText")
39+
.HasColumnType("varchar(200)");
40+
3841
b.Property<long>("TotalWorkedTime")
3942
.HasColumnType("bigint");
4043

44+
b.Property<string>("TotalWorkedTimeText")
45+
.HasColumnType("varchar(200)");
46+
4147
b.Property<string>("WorkItemId")
4248
.HasColumnType("varchar(200)");
4349

0 commit comments

Comments
 (0)