9

Without seeing the rest of your code it's difficult to say how this is used, but I think your function has conflated logic and formatting, and formatting is being done too soon. You should hold onto real date information right up until the edges of your program when that's possible. The following demonstrates one way of keeping dates and moving them to the ...


8

Overall, it looks fine. I probably would've written it a little differently, and I'll explain the differences. import datetime def get_current_quarters(): """A function that returns an array with all the actual year quarters """ current_year = datetime.date.today().year quarter_values = ["31/03/","30/06/...


6

datetime.date has a .replace() method that returns a copy with some values changed. This can be used to get the date 18 years ago. end_date = date.today() start_date = end_date.replace(year=end_date.year - 18) datetime.date.toordinal returns an integer corresponding to the date. The ordinals for the start and stop date can be used in random.randint() to ...


4

upggift1.cc Please don't do this: using namespace std; We have namespaces for good reason, and it's a bad habit to throw away their benefits like that. Date d1; bool create_date_again = true; int temp_date[3]; char garbage; This looks like something written by a (quite old) C programmer. Prefer to declare variables where they can be initialised, rather ...


3

If the goal is to compute a date 10,000 days from now, I would strongly recommend using the std::chrono facilities. If you do, the code would be only a few lines long: #include <iostream> #include <iomanip> #include <ctime> #include <chrono> int main() { using namespace std::chrono; auto later{system_clock::to_time_t(...


2

It's not common practice to use exceptions when validating user input. A simpler approach would be for the Date class to provide a static member function to check whether it's constructible from the given arguments: class Date { public: static is_valid(int y, int m, int d); Date(int y, int m, int d); Then instead of throw/catch, we can read input ...


Only top voted, non community-wiki answers of a minimum length are eligible