Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an absolute or relative time period class in C#
    text
    copied!<p>I want to create some class that can calculate absolute or relative time period.<br> Meaning: the constructor will get either time period and units ( 3 weeks ) or two <code>DateTime</code> start and finish time. I have wrote the following code : </p> <pre><code>public class TimePeriod { public State TimePerriodState { get; private set; } public RelativeTime RelativeTimePeriod { get; private set; } public int UnitsOfTime { get; private set; } public DateTime? StartTime { get; private set; } public DateTime? EndTime { get; private set; } public TimePeriod(RelativeTime relativeTime, int unitsOfTime) { TimePerriodState = State.Absolute; RelativeTimePeriod = relativeTime; UnitsOfTime = unitsOfTime; } public TimePeriod(DateTime startTime , DateTime endTime) { TimePerriodState = State.Relative; StartTime = startTime; EndTime = endTime; } public enum State { None, Absolute, Relative } public enum RelativeTime { None, Hours, Days, Weeks, Months, Year } } </code></pre> <p>But I don't like that the usage is base on the state. In the end the data will appear in the UI as two different controls. Is there a better way of making the API little better? Maybe pass in the data and calculate the dateTime on the fly or some thing like that?</p> <p><strong>UPDATE :</strong></p> <p>the usage is relative to any time its being used. meaning enter a timespan is not possible. lets say we need fo have the relative time prior 10 days from now or fixed days from X to Y</p> <p>The <code>TimeSpan</code> will be calculated in a different BL class (this is a POCO class) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload