Storing fiscal year DateTime
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
We have conception as "fiscal year" and have calculations based on start/end date (April 1, March 31).
My question is: what is better, store end date time as April 1 or March 31?
Now I have next code:
public DateTime GetFiscalYearStart(int fiscalYear)
return new DateTime(fiscalYear, 4, 1);
public DateTime GetFiscalYearEnd(int fiscalYear)
return new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
c# datetime
add a comment |Â
up vote
3
down vote
favorite
We have conception as "fiscal year" and have calculations based on start/end date (April 1, March 31).
My question is: what is better, store end date time as April 1 or March 31?
Now I have next code:
public DateTime GetFiscalYearStart(int fiscalYear)
return new DateTime(fiscalYear, 4, 1);
public DateTime GetFiscalYearEnd(int fiscalYear)
return new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
c# datetime
Just a little note, the more recent versions of C# allow you to simply dopublic DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for<=
and>=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..
â Drag and Drop
Apr 16 at 11:43
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
We have conception as "fiscal year" and have calculations based on start/end date (April 1, March 31).
My question is: what is better, store end date time as April 1 or March 31?
Now I have next code:
public DateTime GetFiscalYearStart(int fiscalYear)
return new DateTime(fiscalYear, 4, 1);
public DateTime GetFiscalYearEnd(int fiscalYear)
return new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
c# datetime
We have conception as "fiscal year" and have calculations based on start/end date (April 1, March 31).
My question is: what is better, store end date time as April 1 or March 31?
Now I have next code:
public DateTime GetFiscalYearStart(int fiscalYear)
return new DateTime(fiscalYear, 4, 1);
public DateTime GetFiscalYearEnd(int fiscalYear)
return new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
c# datetime
edited Apr 16 at 11:19
t3chb0t
32k54195
32k54195
asked Apr 16 at 8:49
Ssss
1183
1183
Just a little note, the more recent versions of C# allow you to simply dopublic DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for<=
and>=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..
â Drag and Drop
Apr 16 at 11:43
add a comment |Â
Just a little note, the more recent versions of C# allow you to simply dopublic DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for<=
and>=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..
â Drag and Drop
Apr 16 at 11:43
Just a little note, the more recent versions of C# allow you to simply do
public DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Just a little note, the more recent versions of C# allow you to simply do
public DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for
<=
and >=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..â Drag and Drop
Apr 16 at 11:43
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for
<=
and >=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..â Drag and Drop
Apr 16 at 11:43
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
It doesn't really matter.
My question is: what is better, store end date time as April 1 or March 31?
This is completely up to you based on what you want:
- How do you prefer to check your date bounds?
- Inclusive?
if(myDate <= myFiscalYear.GetFiscalYearEnd())
- Exclusive?
if(myDate < myFiscalYear.GetFiscalYearEnd())
- Inclusive?
- Is this end date shown to the user? Which date do they prefer seeing?
On a technical level, it doesn't matter which you pick. All that matters is that you handle the value consistently. If you start mixing <
and <=
checks, you're going to run into problems and bugs regardless of whether you define your date inclusive or exclusive.
Taking it a bit further.
However, as I pointed out, the inconsistent use of <
and <=
is going to be a possible cause for bugs down the line. Your developers might mistakenly use one instead of the other.
The issue here is that external code will handle the comparison. However, if you wrap this in a class of your own, you can ensure that the evaluation only occurs in one place, which dramatically lowers the chance of developer error.
A simple example class:
public class FiscalYear
private int fiscalYear;
public DateTime Start => new DateTime(fiscalYear, 4, 1);
public DateTime End => new DateTime(fiscalYear+1, 4, 1).AddTicks(-1);
public FiscalYear(int year)
this.fiscalYear = year;
public bool Contains(DateTime date)
return date >= this.Start && date <= this.End;
Note
There are other possible variations on this. You could calculate the dates in the constructor, or you could calculate the end date based on the start date. How you define the values is completely up to you.
Edit remark:
It's still possible for developers to implement their own evalutation based on the Start/End properties, but that is then considered developer error, they should rely on the logic that already exists instead of reinventing the wheel.
What you could also do is setStart
andEnd
toprivate
. This way, you prevent external code from doing their own evaluation, they can only donew FiscalYear(2018).Contains(myDate)
, but then you do lose out on usingFiscalYear
as an easy way for your external callers to find out what the start and end date of a fiscal year are. That's up to you to decide.
External code can then rely on the existing Contains()
method; which means that the developers of the external code no longer need to know whether they should use <
or <=
.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
It doesn't really matter.
My question is: what is better, store end date time as April 1 or March 31?
This is completely up to you based on what you want:
- How do you prefer to check your date bounds?
- Inclusive?
if(myDate <= myFiscalYear.GetFiscalYearEnd())
- Exclusive?
if(myDate < myFiscalYear.GetFiscalYearEnd())
- Inclusive?
- Is this end date shown to the user? Which date do they prefer seeing?
On a technical level, it doesn't matter which you pick. All that matters is that you handle the value consistently. If you start mixing <
and <=
checks, you're going to run into problems and bugs regardless of whether you define your date inclusive or exclusive.
Taking it a bit further.
However, as I pointed out, the inconsistent use of <
and <=
is going to be a possible cause for bugs down the line. Your developers might mistakenly use one instead of the other.
The issue here is that external code will handle the comparison. However, if you wrap this in a class of your own, you can ensure that the evaluation only occurs in one place, which dramatically lowers the chance of developer error.
A simple example class:
public class FiscalYear
private int fiscalYear;
public DateTime Start => new DateTime(fiscalYear, 4, 1);
public DateTime End => new DateTime(fiscalYear+1, 4, 1).AddTicks(-1);
public FiscalYear(int year)
this.fiscalYear = year;
public bool Contains(DateTime date)
return date >= this.Start && date <= this.End;
Note
There are other possible variations on this. You could calculate the dates in the constructor, or you could calculate the end date based on the start date. How you define the values is completely up to you.
Edit remark:
It's still possible for developers to implement their own evalutation based on the Start/End properties, but that is then considered developer error, they should rely on the logic that already exists instead of reinventing the wheel.
What you could also do is setStart
andEnd
toprivate
. This way, you prevent external code from doing their own evaluation, they can only donew FiscalYear(2018).Contains(myDate)
, but then you do lose out on usingFiscalYear
as an easy way for your external callers to find out what the start and end date of a fiscal year are. That's up to you to decide.
External code can then rely on the existing Contains()
method; which means that the developers of the external code no longer need to know whether they should use <
or <=
.
add a comment |Â
up vote
6
down vote
accepted
It doesn't really matter.
My question is: what is better, store end date time as April 1 or March 31?
This is completely up to you based on what you want:
- How do you prefer to check your date bounds?
- Inclusive?
if(myDate <= myFiscalYear.GetFiscalYearEnd())
- Exclusive?
if(myDate < myFiscalYear.GetFiscalYearEnd())
- Inclusive?
- Is this end date shown to the user? Which date do they prefer seeing?
On a technical level, it doesn't matter which you pick. All that matters is that you handle the value consistently. If you start mixing <
and <=
checks, you're going to run into problems and bugs regardless of whether you define your date inclusive or exclusive.
Taking it a bit further.
However, as I pointed out, the inconsistent use of <
and <=
is going to be a possible cause for bugs down the line. Your developers might mistakenly use one instead of the other.
The issue here is that external code will handle the comparison. However, if you wrap this in a class of your own, you can ensure that the evaluation only occurs in one place, which dramatically lowers the chance of developer error.
A simple example class:
public class FiscalYear
private int fiscalYear;
public DateTime Start => new DateTime(fiscalYear, 4, 1);
public DateTime End => new DateTime(fiscalYear+1, 4, 1).AddTicks(-1);
public FiscalYear(int year)
this.fiscalYear = year;
public bool Contains(DateTime date)
return date >= this.Start && date <= this.End;
Note
There are other possible variations on this. You could calculate the dates in the constructor, or you could calculate the end date based on the start date. How you define the values is completely up to you.
Edit remark:
It's still possible for developers to implement their own evalutation based on the Start/End properties, but that is then considered developer error, they should rely on the logic that already exists instead of reinventing the wheel.
What you could also do is setStart
andEnd
toprivate
. This way, you prevent external code from doing their own evaluation, they can only donew FiscalYear(2018).Contains(myDate)
, but then you do lose out on usingFiscalYear
as an easy way for your external callers to find out what the start and end date of a fiscal year are. That's up to you to decide.
External code can then rely on the existing Contains()
method; which means that the developers of the external code no longer need to know whether they should use <
or <=
.
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
It doesn't really matter.
My question is: what is better, store end date time as April 1 or March 31?
This is completely up to you based on what you want:
- How do you prefer to check your date bounds?
- Inclusive?
if(myDate <= myFiscalYear.GetFiscalYearEnd())
- Exclusive?
if(myDate < myFiscalYear.GetFiscalYearEnd())
- Inclusive?
- Is this end date shown to the user? Which date do they prefer seeing?
On a technical level, it doesn't matter which you pick. All that matters is that you handle the value consistently. If you start mixing <
and <=
checks, you're going to run into problems and bugs regardless of whether you define your date inclusive or exclusive.
Taking it a bit further.
However, as I pointed out, the inconsistent use of <
and <=
is going to be a possible cause for bugs down the line. Your developers might mistakenly use one instead of the other.
The issue here is that external code will handle the comparison. However, if you wrap this in a class of your own, you can ensure that the evaluation only occurs in one place, which dramatically lowers the chance of developer error.
A simple example class:
public class FiscalYear
private int fiscalYear;
public DateTime Start => new DateTime(fiscalYear, 4, 1);
public DateTime End => new DateTime(fiscalYear+1, 4, 1).AddTicks(-1);
public FiscalYear(int year)
this.fiscalYear = year;
public bool Contains(DateTime date)
return date >= this.Start && date <= this.End;
Note
There are other possible variations on this. You could calculate the dates in the constructor, or you could calculate the end date based on the start date. How you define the values is completely up to you.
Edit remark:
It's still possible for developers to implement their own evalutation based on the Start/End properties, but that is then considered developer error, they should rely on the logic that already exists instead of reinventing the wheel.
What you could also do is setStart
andEnd
toprivate
. This way, you prevent external code from doing their own evaluation, they can only donew FiscalYear(2018).Contains(myDate)
, but then you do lose out on usingFiscalYear
as an easy way for your external callers to find out what the start and end date of a fiscal year are. That's up to you to decide.
External code can then rely on the existing Contains()
method; which means that the developers of the external code no longer need to know whether they should use <
or <=
.
It doesn't really matter.
My question is: what is better, store end date time as April 1 or March 31?
This is completely up to you based on what you want:
- How do you prefer to check your date bounds?
- Inclusive?
if(myDate <= myFiscalYear.GetFiscalYearEnd())
- Exclusive?
if(myDate < myFiscalYear.GetFiscalYearEnd())
- Inclusive?
- Is this end date shown to the user? Which date do they prefer seeing?
On a technical level, it doesn't matter which you pick. All that matters is that you handle the value consistently. If you start mixing <
and <=
checks, you're going to run into problems and bugs regardless of whether you define your date inclusive or exclusive.
Taking it a bit further.
However, as I pointed out, the inconsistent use of <
and <=
is going to be a possible cause for bugs down the line. Your developers might mistakenly use one instead of the other.
The issue here is that external code will handle the comparison. However, if you wrap this in a class of your own, you can ensure that the evaluation only occurs in one place, which dramatically lowers the chance of developer error.
A simple example class:
public class FiscalYear
private int fiscalYear;
public DateTime Start => new DateTime(fiscalYear, 4, 1);
public DateTime End => new DateTime(fiscalYear+1, 4, 1).AddTicks(-1);
public FiscalYear(int year)
this.fiscalYear = year;
public bool Contains(DateTime date)
return date >= this.Start && date <= this.End;
Note
There are other possible variations on this. You could calculate the dates in the constructor, or you could calculate the end date based on the start date. How you define the values is completely up to you.
Edit remark:
It's still possible for developers to implement their own evalutation based on the Start/End properties, but that is then considered developer error, they should rely on the logic that already exists instead of reinventing the wheel.
What you could also do is setStart
andEnd
toprivate
. This way, you prevent external code from doing their own evaluation, they can only donew FiscalYear(2018).Contains(myDate)
, but then you do lose out on usingFiscalYear
as an easy way for your external callers to find out what the start and end date of a fiscal year are. That's up to you to decide.
External code can then rely on the existing Contains()
method; which means that the developers of the external code no longer need to know whether they should use <
or <=
.
edited Apr 16 at 12:50
answered Apr 16 at 11:05
Flater
2,645718
2,645718
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f192176%2fstoring-fiscal-year-datetime%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Just a little note, the more recent versions of C# allow you to simply do
public DateTime GetFiscalYearEnd(int fiscalYear) => new DateTime(++fiscalYear, 4, 1).AddTicks(-1);
â Danny Goodall
Apr 16 at 10:07
Off topics comment, Imo as I learn to stay away from sql between so the "March 31" is for me the way to go. for
<=
and>=
should be use with consitency. Ticks -1 should be the prefered way for anyone that ever use sql Eomonth() and between..â Drag and Drop
Apr 16 at 11:43