Should time range checks be inclusive or exclusive?












3















The general convention for a generic range (x,y) is that x is inclusive and y is exclusive.



For Python datetime.time type, datetime.time.max is time(23, 59, 59, 999999), so it doesn't seem to allow to use the conventional range check on the upper end. For example, if I want to check a time range between 10 am and midnight, I might want a range like this: (time(10), time(24)). But time(24) is not valid, even as a sentinel value.



On the other hand, we can't make x exclusive and y inclusive, because then we lose time(0) as a value.



Should range checks on time be inclusive? Something about it doesn't seem right to me, but I can't articulate it.










share|improve this question




















  • 1





    If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

    – 0x5453
    Jan 18 at 18:55








  • 1





    I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

    – Kevin
    Jan 18 at 18:58






  • 3





    I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

    – wim
    Jan 18 at 18:59













  • Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

    – jacob
    Jan 18 at 19:23


















3















The general convention for a generic range (x,y) is that x is inclusive and y is exclusive.



For Python datetime.time type, datetime.time.max is time(23, 59, 59, 999999), so it doesn't seem to allow to use the conventional range check on the upper end. For example, if I want to check a time range between 10 am and midnight, I might want a range like this: (time(10), time(24)). But time(24) is not valid, even as a sentinel value.



On the other hand, we can't make x exclusive and y inclusive, because then we lose time(0) as a value.



Should range checks on time be inclusive? Something about it doesn't seem right to me, but I can't articulate it.










share|improve this question




















  • 1





    If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

    – 0x5453
    Jan 18 at 18:55








  • 1





    I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

    – Kevin
    Jan 18 at 18:58






  • 3





    I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

    – wim
    Jan 18 at 18:59













  • Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

    – jacob
    Jan 18 at 19:23
















3












3








3








The general convention for a generic range (x,y) is that x is inclusive and y is exclusive.



For Python datetime.time type, datetime.time.max is time(23, 59, 59, 999999), so it doesn't seem to allow to use the conventional range check on the upper end. For example, if I want to check a time range between 10 am and midnight, I might want a range like this: (time(10), time(24)). But time(24) is not valid, even as a sentinel value.



On the other hand, we can't make x exclusive and y inclusive, because then we lose time(0) as a value.



Should range checks on time be inclusive? Something about it doesn't seem right to me, but I can't articulate it.










share|improve this question
















The general convention for a generic range (x,y) is that x is inclusive and y is exclusive.



For Python datetime.time type, datetime.time.max is time(23, 59, 59, 999999), so it doesn't seem to allow to use the conventional range check on the upper end. For example, if I want to check a time range between 10 am and midnight, I might want a range like this: (time(10), time(24)). But time(24) is not valid, even as a sentinel value.



On the other hand, we can't make x exclusive and y inclusive, because then we lose time(0) as a value.



Should range checks on time be inclusive? Something about it doesn't seem right to me, but I can't articulate it.







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 18:53









wim

160k50306437




160k50306437










asked Jan 18 at 18:50









jacobjacob

1,002924




1,002924








  • 1





    If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

    – 0x5453
    Jan 18 at 18:55








  • 1





    I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

    – Kevin
    Jan 18 at 18:58






  • 3





    I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

    – wim
    Jan 18 at 18:59













  • Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

    – jacob
    Jan 18 at 19:23
















  • 1





    If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

    – 0x5453
    Jan 18 at 18:55








  • 1





    I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

    – Kevin
    Jan 18 at 18:58






  • 3





    I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

    – wim
    Jan 18 at 18:59













  • Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

    – jacob
    Jan 18 at 19:23










1




1





If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

– 0x5453
Jan 18 at 18:55







If you use datetime instead of time you can use midnight of the following day as your upper bound. But if you don't actually care about the date you would need a dummy value there (1970-1-1 and 1970-1-2, maybe?) which is a bit of a hack.

– 0x5453
Jan 18 at 18:55






1




1





I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

– Kevin
Jan 18 at 18:58





I notice that the error message for datetime.time(24) is ValueError: hour must be in 0..23. Since 0 and 23 are both permissible values, this may indicate the author's preference about incluvisity of end points in the context of times.

– Kevin
Jan 18 at 18:58




3




3





I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

– wim
Jan 18 at 18:59







I suppose the issue does not really come up in practice, because you would not generally check a time in a finite range of time values. You would check it by using inequalities, so choosing < or <= as you want. For same reason we don't check floats in a range of floats.

– wim
Jan 18 at 18:59















Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

– jacob
Jan 18 at 19:23







Thanks all. I appreciate all the thoughts expressed here. It seems that the practical approach to time ranges depends on the context of the problem.

– jacob
Jan 18 at 19:23














0






active

oldest

votes











Your Answer






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: "1"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54259865%2fshould-time-range-checks-be-inclusive-or-exclusive%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54259865%2fshould-time-range-checks-be-inclusive-or-exclusive%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Callistus III

Plistias Cous

Index Sanctorum