New answers tagged

-3

function getWDays($startDate,$holidays,$wDays) { // using + weekdays excludes weekends $new_date = date('Y-m-d', strtotime("{$startDate} +{$wDays} weekdays")); foreach($holidays as $holiday) { $holiday_ts = strtotime($holiday); // if holiday falls between start date and new date, then account for ...


-2

count=0 p = int(input("Enter number of days in month:")) q = int(input("Enter the starting day(0-6):")) print("S M T W T F S") print(" "*q,end="") count=q for i in range(1,p+1): count=count+1 if count <= 7: if i<=9: print(i,end=' ') else: print(i,end=' ') else: count=0 ...


7

Exception If your algorithm cannot find a date, it is easier to raise an Exception than to return ''. Returning sentinel values instead of exceptions can lead to unexpected behaviour if the user of this function does not test for this sentinel value. comments Comments should explain why you did something, not how. # Take the last four digits tells you ...


2

Any better/simple solution to do this ? Yes. Functionality now built-in. java.time.LocalDate::datesUntil ➙ Stream of LocalDate objects The modern approach uses java.time classes. The java.time.LocalDate has built-in support for generating a stream of dates. Call LocalDate::datesUntil. I do not know Scala, so here is Java syntax. LocalDate today = ...


3

Firstly, I must apologies that my German understanding isn't fluent enough to read all your comments. I think your intuition is right that you ought to be using functions rather than preprocessor macros - the latter are just too fragile, and anyway, good compilers are able to inline functions. I would recommend -O3 -march=native in your GCC flags if speed ...


1

Should I do away with the #defines and use functions instead? Probably. Speed is everything. No functions. Just #defines. Are you so sure? Have you tested the speed of your application when using regular functions? Optimizing C compilers are pretty good. They'll be able to inline away the functions that you write. Defaulting to writing #define macros ...


Top 50 recent answers are included