All Questions
75 questions
7
votes
2
answers
2k
views
Date Checking in C++
I am working on one of my assignments (Hash Tables) for my Data Structures class(1st year), the assignment focuses on OOP and understanding of Hash Tables.
Restrictions:
Usage of raw pointers
C++11 ...
2
votes
2
answers
195
views
Algorithm that prints day, when submitted date
I would love to know your opinion about this algorithm that we wrote in class. I was thinking about how I can optimize it (in terms of size of code/complexity) without using library functions (...
2
votes
1
answer
893
views
Unix epoch seconds corresponding to midnight in a local time zone
I came up with the following function to obtain epoch seconds that correspond to previous midnight in a local time zone:
...
3
votes
1
answer
167
views
Constraining a templated method to accept any integral std::chrono::time_point
Recently I was writing a class that had overloaded read methods for various data types. One of the sets of types I wanted to handle were integral ...
1
vote
1
answer
10k
views
Convert string to date C++
New to C++ here, by combining different pieces of code I've found, i came with this solution below to convert a date in string to a date object. It works as I want but I'm not certain to do the ...
0
votes
2
answers
741
views
Create a formatted calendar
I'm working on a project that creates a calendar based on user input of a month and a year. With that information, the code should count the number of days in that month and output a calendar. I would ...
0
votes
2
answers
744
views
Year/month difference calculator
My program calculates the user's age in years and months. It takes the user's birth year and month and then the current year and month as input.
...
3
votes
3
answers
450
views
Add 10000 days to a date
I'm currently doing old exams from my course to train for my upcoming exam. What I'm wondering is about a code block which I will specify after I've presented the different files with code.
//...
4
votes
1
answer
2k
views
Stop Watch class in C++ using chrono
I have written a class that acts like a stopwatch using C++11's std::chrono library. I wrote this because I find it difficult to benchmark my cpp code properly, ...
1
vote
2
answers
139
views
Date Class, implemented
I'm implementing this date class based on <ctime>
I'll appreciate your comments, critics and advice.
Please review, thank you!.
Date.h
...
3
votes
3
answers
11k
views
HackerRank Time Conversion solution
The challenge (PDF) is to convert a time from 12-hour format (hh:mm:ssAM or hh:mm:ssPM) to 24-hour format.
This is my solution, ...
3
votes
2
answers
197
views
"When to take medicine" CodeChef Challenge MEDIC
I just submitted this code to solve the "When to take medicine" challenge on CodeChef:
...
4
votes
1
answer
77
views
Generic calendar which can hold Mayan, Babylonian, Fantasy, Gregorian calendars
I have created this generic calendar class which I call a TimePeriodGrouping. It can contain a series of interlocking time periods (i.e. years, months, days, hours...). When time is added to one of ...
2
votes
0
answers
817
views
A portable cross platform C++17 method to retrieve the current date and time
I am working on a utility function to get the current date and time. My objective is to do this in a generic and portable way. I would like to stay way from platform specific code to allow the ...
-2
votes
3
answers
362
views
Translate a day in year to month and day 2nd method
Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1.
I've already submitted my ...
1
vote
1
answer
855
views
Translate a day in year to month and day
Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1.
This is what I came up with. ...
4
votes
5
answers
165
views
Leap year determination using guard clause
I have a function to check the leap year as follows
...
2
votes
1
answer
823
views
11
votes
1
answer
294
views
CodeVita challenge: forming the latest valid datetime in a year using some given digits
After answering someone's Code Review question, I decided to tackle a sequel:
Given an input consisting of 12 non-decreasing single digits separated by commas, form the latest valid date time in a ...
6
votes
2
answers
8k
views
Calendar for any given month/year
This is one of my first C++ training project where I created the console application which displays the calendar of any given month.
I observed how offset of days (empty places on the calendar) ...
14
votes
4
answers
6k
views
Date class implementation in C++
Here is my implementation of a Date class.
I am interested mainly in the class implementation and design, whether or not it has any major drawbacks and inefficiencies. But I will appreciate any given ...
10
votes
1
answer
5k
views
Stopwatch class in C++
I needed to implement a stop watch like class that will be used to measure running time of different functions by others. The final running time needs to be printed in 9h 3min 2s 23s 32ms 87us 78ns ...
8
votes
2
answers
1k
views
Digital clock with many functions
I made a digital clock with the use of an RTC (DS3231) and an LCD (16x2).
Current functions:
Display time
Display date (different formats)
Display temperature (Celsius and Fahrenheit)
Display day ...
4
votes
2
answers
1k
views
Countdown timer for new year
Please help me improve my code. Note that it runs just fine. Especially with the way I use SFML, I need lots of guidance since I've just started learning how to use this library. I'm still learning C++...
6
votes
5
answers
27k
views
Date class in C++
This is a Date class in C++. I didn't use C++ strings because I'm not sure if I'm allowed to. It seems to work fine, but I'm wondering if there are any errors I ...
23
votes
8
answers
3k
views
Area of the triangle generated by the hands of a clock
Problem explanation:
Let’s suppose we have a clock that has an hour hand 3 units long, a minute hand 4 units long, and a second hand 5 units long. The hour hand moves once every hour, the minute hand ...
5
votes
2
answers
2k
views
A Date Class with simple methods
This is homework from one MOOC(no requirement of forbidding paste codes online).
The title gave me a framework:
...
2
votes
0
answers
72
views
PDcurses clock using abstract factory design
I am currently learning how to use PDcurses and decided to make a clock with it. **NOTE: this Watch that uses the abstract factory design pattern is not the same as this question!!. This question is a ...
3
votes
1
answer
18k
views
Getting current timezone
My goal is to precisely calculate the current timezone using C++ standard library, represented as the difference (in seconds) between GMT time and local time.
Example: Italy is GMT+1 so my expected ...
5
votes
2
answers
764
views
Stopwatch that uses the abstract factory design pattern
I have wrote code for a stopwatch that utilizes the abstract design pattern and would like to get some feedback on the code, so be as harsh as you can.
Note: I used ...
2
votes
0
answers
1k
views
Optimize platform independent GetTickCount()
I used this method as a platform independent tick counter. Unfortunately, it consumes ~10 % cpu time in one of my methods. Is there a faster way to solve the issue?
...
3
votes
2
answers
10k
views
Printing facility for std::chrono::time_point
Motivation:
It is known that std::time_point<...> cannot be streamed directly using operator<<(), which is pretty ...
3
votes
1
answer
6k
views
Given a date and a duration, calculate the future date
The question is basically like this:
Given year, month, day and duration, calculate the future date based on given data and duration. The given date guarantees to be after 1900-01-01, and the duration ...
5
votes
3
answers
238
views
Print the name of day
How can I improve this code? It takes a number in the range of [1,7] and prints its corresponding day.
...
10
votes
2
answers
32k
views
Converting std::chrono::time_point to/from std::string
Consider these functions that allow to convert std::chrono::time_point to/from std::string with a predefined date-time format.
<...
1
vote
1
answer
105
views
Date class for Budgeting App
This is a Date class I made for a hobby project. It does not deal with time at all; that is, the smallest unit of time it considers is one day, and no concern with time zones.
Where I do most of my ...
4
votes
3
answers
4k
views
Simple days between dates calculator
I recently decided to try my hand at this problem of calculating the number of days between two given dates including leap years in the calculation. I chose to do it in C++ as it is the language I ...
2
votes
2
answers
17k
views
time_t to string
...
5
votes
3
answers
127
views
Scheduling a task into a period within a day, depending on whether or not it is a weekend
I have a function which needs to detect part of the day depending on whether it's the weekend or not (the weekend affects the lunch time indication). The method is quite long and I'd like to know how ...
5
votes
1
answer
5k
views
Create monthly calendar with number of days and offset (day of week) as user input
I am taking a beginning programming class and have been given the assignment to create a calendar as described in the title. Per the assignment the user entering offset of 0 will begin the calendar ...
3
votes
2
answers
1k
views
Formatting seconds as days hours minutes seconds
I have the below and it gives me the desired output (ie; 1 day 12:05:33) but it looks overly complicated, is there a more straight forward way of doing this with the least amount of string ...
6
votes
2
answers
4k
views
Formatting seconds as hours:minutes:seconds
This is basically my school homework and I want to know what to improve, and what not to do.
The homework basically is this:
You will get a input in seconds, which is supposed to be shown as H:MM:SS ...
4
votes
1
answer
3k
views
C++ time types and format conversions
I wrote a small header-only C++11 header for converting between various C++ time formats:
...
15
votes
4
answers
3k
views
Enter year, date, and month in any order, I'll organize it
I would like some advice on how I could make it less repetitive and use more functions and classes.
...
7
votes
1
answer
519
views
C++ calendar printer
I was at CppCon last week and watched a clever talk about using ranges and calendars. This is just me trying to play around with the new technology.
Step 1: dump out a calendar.
Usage:
...
0
votes
1
answer
103
views
Designing a generic C++1z class [closed]
I'm designing a generic interface for a MessageEntry class for a .h file.
I'm looking for guidance on form and terminology (would I call this an interface/template/generic class?):
...
3
votes
2
answers
155
views
Implementing a Yearmonth class
Recently I wrote a program that was required to handle year and month data and so I wrote this class to encapsulate that handling. What I needed was a way to initialize the ...
1
vote
1
answer
2k
views
Track execution time using std::chrono facilities and print the execution time in a comprehensible way
The class below will be used to track the execution time of various operations. There is no need to dip into C libraries to get formatted output then.
Output would be something like this:
10 ...
2
votes
2
answers
10k
views
Input and Validate Dates
Question:
Write a function that accepts integer values for day, month and year and returns them in a valid format. If the day is above 30, then convert it to 30. If the month is above 12 then ...
9
votes
2
answers
613
views
Calculating epoch seconds
Below I have code that calculates epoch seconds. It is built to try to change run time checks into asserts in order to give performance in production. I want to make sure all the edge cases are ...