1

I had a client that wanted an online pizza shop, and he also didn't want customers to place orders after opening hours - of course. I made just a little simple script for that, that I thought I might share with anyone who wants that in the future.

Daniel Holm
  • 4,347
  • 3
  • 19
  • 27
  • 2
    Quite nice of you to share that with us Daniel, however you are getting downvoted (NOT by me) from this. People may think it is not the place to share code, but for problems one may be having with code. I suggest you delete your question, before you start getting more downvotes, cheers. – Funk Forty Niner Jul 31 '13 at 15:57
  • Use `pastebin` or `gist`... – Maciej A. Czyzewski Jul 31 '13 at 16:03
  • @Fred, self-answered questions are fine here. Admittedly, it's better to phrase the original question as an actual question, but I can imagine that other people may have a use for this, which is the whole purpose of Stack Overflow. – halfer Jul 31 '13 at 16:17
  • @Maciej: no, links to pastebins are discouraged here. They make for brittle questions that are useless if the link breaks, which happens often. External links are okay if they are supplementary to the question/answer, but not if the text absolutely relies on it. – halfer Jul 31 '13 at 16:19
  • 1
    @halfer **I quote the OP:** *"I made just a little simple script for that, that I thought I might share with anyone who wants that in the future."* - The operative word here, being **"share".** This is clearly not a question. I do agree with what you said though about "self-answered questions" sure, but this is clearly not a problem with code that the OP is experiencing. – Funk Forty Niner Jul 31 '13 at 16:32
  • @halfer (addendum) You even said it yourself on your profile: *"how to ask QUESTIONS on StackOverflow"* - It's about asking questions, not "SHARING" code. – Funk Forty Niner Jul 31 '13 at 16:37
  • 1
    @halfer I think what `Maciej` meant about those were, to use those (code services) as a means to store shareable code, and not to necessarily post those links on SO. – Funk Forty Niner Jul 31 '13 at 16:43
  • @MaciejCzyżewski Am I right on this? (see comment above this one). – Funk Forty Niner Jul 31 '13 at 16:44
  • Yes. I agree with @Fred! – Maciej A. Czyzewski Jul 31 '13 at 16:46
  • `@ALL` If an SO member wants to share code, then I think a probable/acceptable way to do so, would be to include that information on his/her profile, such as: **"Hi, and welcome to my profile on SO. I have been coding for a while, and here are a few links to the work I have done".** – Funk Forty Niner Jul 31 '13 at 16:50
  • @MaciejCzyżewski What do you think about my comment above to `ALL`? – Funk Forty Niner Jul 31 '13 at 16:56
  • @halfer What do you think about my comment above to `@ALL`? – Funk Forty Niner Jul 31 '13 at 16:56
  • 1
    Hi @Fred. In general, what is permissible is dictated partly by site guidelines and partly by how the community feels (and the latter changes over time `;-)`). I think my view above is broadly reflected [here](http://meta.stackexchange.com/q/22706/184183) and [here](http://meta.stackexchange.com/q/13128/184183). However, if an OP wants their code reviewed, [that can go on a different site](http://meta.stackexchange.com/q/175799/184183). If you feel very strongly about it, you can always ask a new question on _Meta_. – halfer Jul 31 '13 at 21:33
  • This is a QA site, and you are expected to post questions. – jb. Jul 31 '13 at 22:08
  • @halfer I will agree with you to a certain degree. Your links to posts you included make sense, sure and were appreciated. However, had the OP worded his post differently, then I would've shrugged it off and not say anything more than my *"nice of you to share this"*. It was nice of him to do so, yet from what I've gathered on SO and its "what it is about", seems as if there's more to it than I thought. There are people who feel much more strongly about it than I do, so I shouldn't be one to "carry their cross", as it were. Notice now that he's gotten another downvote. I NOT being one of them. – Funk Forty Niner Aug 01 '13 at 00:15

1 Answers1

7
<?php
    date_default_timezone_set('Europe/Stockholm'); // timezone 

    $weekday = date('l'); // today 
    //print $weekday; // Debug
    //print date("H:i"); // debug

    // Set open and closing time for each day of the week
    if ($weekday == "Friday") {
        $open_from = "11:00";
        $opten_to = "21:45";
    }
    elseif ($weekday == "Saturday" || $weekday == "Sunday") {
        $open_from = "12:00";
        $open_to = "21:45";
    }
    else {
        $open_from = "11:00";
        $open_to = "20:45";
    }

    // now check if the current time is before or after opening hours
    if (date("H:i") < $open_from || date("H:i") > $open_to ) {
        echo "Closed!";
    }

    // show the checkout button
    else {
        echo "Open!";
    }
?>
João Teixeira
  • 119
  • 1
  • 12
Daniel Holm
  • 4,347
  • 3
  • 19
  • 27