You need to write a function isValidDate ($ date) with the following conditions: {code ...} when I wrote the second condition, I found that the time covered by the condition seemed to be a bit problematic. I 'd like to see your opinions.
You need to write a function isValidDate ($ date) with the following conditions:
Function isValidDate ($ date) {// 1. $ date is the week + time () before on the day before $ date = true // 2. $ date: + time () next week. it must be = true after six o'clock P.M. this Thursday. // 3. otherwise, false is returned. (Note: One week starts from Monday) $ orderTime = strtotime ($ date); $ now = time (); if (date ('W', $ orderTime) = date ('W', $ now) & (strtotime ($ date, $ now)-$ now)> 86400/4) // book on the previous day, closing reservation {return true;} if (date ('W', $ orderTime) = date ('W', $ now) + 1 & $ now> strtotime ('Saturday six o'clock P.M.-2 Day', $ now) // book for the second week, Thursday and later {return true;} return false ;}
When I wrote the second condition, I found that the time covered by the condition seemed to be a bit problematic. I 'd like to see your opinions.
Reply content:
You need to write a function isValidDate ($ date) with the following conditions:
Function isValidDate ($ date) {// 1. $ date is the week + time () before on the day before $ date = true // 2. $ date: + time () next week. it must be = true after six o'clock P.M. this Thursday. // 3. otherwise, false is returned. (Note: One week starts from Monday) $ orderTime = strtotime ($ date); $ now = time (); if (date ('W', $ orderTime) = date ('W', $ now) & (strtotime ($ date, $ now)-$ now)> 86400/4) // book on the previous day, closing reservation {return true;} if (date ('W', $ orderTime) = date ('W', $ now) + 1 & $ now> strtotime ('Saturday six o'clock P.M.-2 Day', $ now) // book for the second week, Thursday and later {return true;} return false ;}
When I wrote the second condition, I found that the time covered by the condition seemed to be a bit problematic. I 'd like to see your opinions.
How do you feel that this is mandatory for other people to do interview questions? Since the organization can be listed as 123, the implementation should not be a problem...
Install Carbon
Use Carbon \ Carbon;/*** verification date * @ param string $ date * @ return boolean */function isValidDate ($ date) {// $ date is the time of the week + time () before on the day before $ date = true if (Carbon: parse ($ date)-> format ('w ') = Carbon: now ()-> format ('w') & time () <Carbon: parse ($ date)-> subDay (1) -> hour (18)-> minute (0)-> timestamp) {return true;} // $ date is next week + time () to = true elseif (Carbon: parse ($ date)-> format ('w') = Carbon: now ()-> addWeek (1) after six o'clock P.M. this Thursday) -> format ('w') & time ()> Carbon: now ()-> startOfDay ()-> addDay (3)-> hour (18) -> minute (0)-> timestamp) {return true;} return false ;}
Simply change the subject'sIf statement return
Function isValidDate ($ date) {// 1. $ date is the week + time () before on the day before $ date = true // 2. $ date: + time () next week. it must be = true after six o'clock P.M. this Thursday. // 3. otherwise, false is returned. (Note: One week starts from Monday) $ orderTime = strtotime ($ date); $ now = time (); if (date ('W', $ orderTime) === date ('W', $ now) // Current week {// time () = true return $ now <strtotime (date ('Y-m-d 18:00:00 ', strtotime ("$ date-1 day");} if (date ('W', $ orderTime) ==( date ('W', $ now) + 1) // next week {// time () to = true return $ now> strtotime (date ('Y-m-d six o'clock P.M ', strtotime ('+ '. 4-date ('w '). 'Days ');} return false ;}