6

You should look into the TimeSpan struct, which provides a nice method TimeSpan.FromSeconds(). Having filled a TimeSpan struct by e.g calling the FromSeconds() method, you can just access its properties Seconds, Minutes and Hours. Instead of concating strings like you do, you should consider to use a StringBuilder. To get rid of the If ... Else If you ...


3

This post on Stack Overflow explains why you are getting the wrong years. https://stackoverflow.com/questions/37766353/pandas-to-datetime-parsing-wrong-year Based on your code all of the two digit years in your data set will be converted to 19XX years. The only problem I can see is that if your data set includes dates across both centuries ( 19XX and 20XX) ...


2

Extract day.title() to a separate method. In this case, if you wanted to change how you store the days of the weeks (e.g. Monday, Tuesday ... -> monday, tuesday...), you would have to change day.title() to day.lower() only in one place*. Implement set_start_and_end() by calling set_start() and set_end(). Identically for getters. The rationale is similar to ...


2

As @Hesclacher has given a fantastic answer, which is not only one that I have upvoted but I would personally mark it as the correct answer if I had the power, I am hesitant to improve upon it. But I would like to offer constructive feedback on your original code. I have a personal distinction between being a VB Coder and a .NET Developer. I think you can ...


1

whole algorithmic change => \$O(n)\$ Your existing algorithm is quite confusing. Perhaps instead you could try a simpler structure such as: from datetime import date def num_sundays_on_first_of_month(year1, year2): num_sundays = 0 for i in range(year1, year2+1): for j in range(1, 13): if date(i, j, 1).weekday() == 6: ...


1

To help with readability, I'd just import datetime.datetime and then alias it, that way you aren't typing datetime.datetime all over the place: from datetime import datetime as dt def time_converter(time): midday_dt = dt.strptime('12:00','%H:%M') time_dt = dt.strptime(time, '%H:%M') if time_dt >= midday_dt: if time_dt >= dt....


1

It might be overkill for just the task at hand, but I've found it useful to write an overload of operator>> to read and match a string literal: std::istream &operator>>(std::istream &is, char const *s) { while (*s && *s == is.peek()) { ++s; is.ignore(1); } if (*s != '\0') is.setstate(std::...


1

You don't check whether the input is invalid. Try to extract useful well-named functions, like int days(int month, int year) and bool is_leap_year(int year). You can extract the numbers directly from std::cin, the colon will be left behind. And the colon can thereafter be extracted like any other single character. As an aside, using scanf() would probably be ...


1

Building on @RickDavin. VB.Net also has a robust If() function that shortcuts the checks (unlike VBA's IIf() function) If hours = 1 Then hourString = Cstr(hours) & " hour" Else If hours > 1 Then hourString = Cstr(hours) & " hours" End If Becomes hourstring = If(hours = 1, "hour", "hours") @Heslacher's function can then be: Private ...


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