Tiny app to track working time on Jira tickets

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.



I was just wanting to get some comments on my code for educational purpose and self-improvement.



Example



enter image description here



Code



using System;
using System.Windows;
using System.Windows.Threading;

namespace Timer
public partial class MainWindow : Window

private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;

public MainWindow()

InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;


private void PauseTimer(object sender, RoutedEventArgs e)

if (!IsTimerPaused)

timer.IsEnabled = false;
PauseButton.Content = "Resume";

else

timer.IsEnabled = true;
PauseButton.Content = "Pause";

IsTimerPaused = !IsTimerPaused;


private void ResetTimer(object sender, RoutedEventArgs e)

timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();


private void StartTimer(object sender, EventArgs e)

if (IsTimerStarted) return;

ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();



private void ToggleStartButton()

StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;


private void IncreaseCounter(object sender, EventArgs e)

counter++;
DisplayTimer();


private void DisplayTimer()

string timeEllapsed;
int seconds;
int minutes;

if (counter <= 60)

seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)

minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";

else

var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";


TimerTextBox.Text = timeEllapsed;









share|improve this question





















  • Why not use Stopwatch?
    – paparazzo
    Feb 12 at 12:39
















up vote
1
down vote

favorite












I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.



I was just wanting to get some comments on my code for educational purpose and self-improvement.



Example



enter image description here



Code



using System;
using System.Windows;
using System.Windows.Threading;

namespace Timer
public partial class MainWindow : Window

private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;

public MainWindow()

InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;


private void PauseTimer(object sender, RoutedEventArgs e)

if (!IsTimerPaused)

timer.IsEnabled = false;
PauseButton.Content = "Resume";

else

timer.IsEnabled = true;
PauseButton.Content = "Pause";

IsTimerPaused = !IsTimerPaused;


private void ResetTimer(object sender, RoutedEventArgs e)

timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();


private void StartTimer(object sender, EventArgs e)

if (IsTimerStarted) return;

ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();



private void ToggleStartButton()

StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;


private void IncreaseCounter(object sender, EventArgs e)

counter++;
DisplayTimer();


private void DisplayTimer()

string timeEllapsed;
int seconds;
int minutes;

if (counter <= 60)

seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)

minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";

else

var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";


TimerTextBox.Text = timeEllapsed;









share|improve this question





















  • Why not use Stopwatch?
    – paparazzo
    Feb 12 at 12:39












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.



I was just wanting to get some comments on my code for educational purpose and self-improvement.



Example



enter image description here



Code



using System;
using System.Windows;
using System.Windows.Threading;

namespace Timer
public partial class MainWindow : Window

private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;

public MainWindow()

InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;


private void PauseTimer(object sender, RoutedEventArgs e)

if (!IsTimerPaused)

timer.IsEnabled = false;
PauseButton.Content = "Resume";

else

timer.IsEnabled = true;
PauseButton.Content = "Pause";

IsTimerPaused = !IsTimerPaused;


private void ResetTimer(object sender, RoutedEventArgs e)

timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();


private void StartTimer(object sender, EventArgs e)

if (IsTimerStarted) return;

ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();



private void ToggleStartButton()

StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;


private void IncreaseCounter(object sender, EventArgs e)

counter++;
DisplayTimer();


private void DisplayTimer()

string timeEllapsed;
int seconds;
int minutes;

if (counter <= 60)

seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)

minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";

else

var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";


TimerTextBox.Text = timeEllapsed;









share|improve this question













I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.



I was just wanting to get some comments on my code for educational purpose and self-improvement.



Example



enter image description here



Code



using System;
using System.Windows;
using System.Windows.Threading;

namespace Timer
public partial class MainWindow : Window

private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;

public MainWindow()

InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;


private void PauseTimer(object sender, RoutedEventArgs e)

if (!IsTimerPaused)

timer.IsEnabled = false;
PauseButton.Content = "Resume";

else

timer.IsEnabled = true;
PauseButton.Content = "Pause";

IsTimerPaused = !IsTimerPaused;


private void ResetTimer(object sender, RoutedEventArgs e)

timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();


private void StartTimer(object sender, EventArgs e)

if (IsTimerStarted) return;

ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();



private void ToggleStartButton()

StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;


private void IncreaseCounter(object sender, EventArgs e)

counter++;
DisplayTimer();


private void DisplayTimer()

string timeEllapsed;
int seconds;
int minutes;

if (counter <= 60)

seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)

minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";

else

var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";


TimerTextBox.Text = timeEllapsed;











share|improve this question












share|improve this question




share|improve this question








edited Feb 10 at 20:20









Jamal♦

30.1k11114225




30.1k11114225









asked Feb 10 at 18:14









Chingiz Mizambekov

62




62











  • Why not use Stopwatch?
    – paparazzo
    Feb 12 at 12:39
















  • Why not use Stopwatch?
    – paparazzo
    Feb 12 at 12:39















Why not use Stopwatch?
– paparazzo
Feb 12 at 12:39




Why not use Stopwatch?
– paparazzo
Feb 12 at 12:39















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187269%2ftiny-app-to-track-working-time-on-jira-tickets%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187269%2ftiny-app-to-track-working-time-on-jira-tickets%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Python Lists

Aion

JavaScript Array Iteration Methods