Storing fiscal year DateTime

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
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);







share|improve this question





















  • 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

















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);







share|improve this question





















  • 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













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);







share|improve this question













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);









share|improve this question












share|improve this question




share|improve this question








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 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

















  • 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
















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











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())


  • 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 set Start and End to private. This way, you prevent external code from doing their own evaluation, they can only do new FiscalYear(2018).Contains(myDate), but then you do lose out on using FiscalYear 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 <=.






share|improve this answer























    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%2f192176%2fstoring-fiscal-year-datetime%23new-answer', 'question_page');

    );

    Post as a guest






























    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())


    • 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 set Start and End to private. This way, you prevent external code from doing their own evaluation, they can only do new FiscalYear(2018).Contains(myDate), but then you do lose out on using FiscalYear 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 <=.






    share|improve this answer



























      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())


      • 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 set Start and End to private. This way, you prevent external code from doing their own evaluation, they can only do new FiscalYear(2018).Contains(myDate), but then you do lose out on using FiscalYear 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 <=.






      share|improve this answer

























        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())


        • 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 set Start and End to private. This way, you prevent external code from doing their own evaluation, they can only do new FiscalYear(2018).Contains(myDate), but then you do lose out on using FiscalYear 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 <=.






        share|improve this answer















        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())


        • 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 set Start and End to private. This way, you prevent external code from doing their own evaluation, they can only do new FiscalYear(2018).Contains(myDate), but then you do lose out on using FiscalYear 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 <=.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Apr 16 at 12:50


























        answered Apr 16 at 11:05









        Flater

        2,645718




        2,645718






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Chat program with C++ and SFML

            Function to Return a JSON Like Objects Using VBA Collections and Arrays

            Will my employers contract hold up in court?