DateTime objects in many programming languages describe an instant in time, expressed as a date and time of day. Use on questions about reviewing code involving date/time logic.

learn more… | top users | synonyms

3
votes
2answers
218 views

Adjusting dates in an array based on a start date

I have a data structure like this which holds start/end dates: ...
4
votes
1answer
30 views

Handling date rollover in same function

I have a program that specifies when an alarm should be active (say, 10AM to 8PM). Part of my program then checks if the alarm is active right now. The "is it active" checker needs to deal with alarm ...
3
votes
2answers
47 views

Custom UUID based on time

I've been using random UUIDs—from Rust, e.g. Uuid::new_v4()—for my primary keys in a MySQL database. I recently happened across this, which suggests ...
3
votes
1answer
82 views

Calculating the angle between the clock's hour and minute hands with unit testing

I am learning PHP OOP and unit testing so I made a code using OOP and TDD approach where it calculates the degree of and angle betwee the clock's hour and minute hands. I would like to know: Is the ...
2
votes
2answers
84 views

Convert hours and minutes to total minutes

This is a simple exercise in C designed to work on IO. The purpose of the program is simple: convert a number of hours and minutes to a total number of minutes. ...
2
votes
3answers
42 views

Get the difference between two dates, in the most convenient unit

I use the following code in Javascript to get the difference between two Date objects. I want the result to return the difference in: seconds if the result is less than 60 secs minutes if the result ...
-3
votes
0answers
56 views

Logging to rolling log files named with timestamps

I wrote a small app to generate tons of logs. By spec log-files must be re-created every X minutes and named as app_%d-%m-%Y_%H:%i.log. This app is work well, but ...
3
votes
3answers
200 views

Transforming tuple with (int month, int year) in string “mm/yyyy”

I would like to improve the following code: ...
3
votes
2answers
83 views

Python Day Finder

I have made a Python program to find the day of the week of an inputted date. I did not want to use the time or datetime module, ...
2
votes
3answers
91 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 ...
5
votes
1answer
71 views

Track hours worked total or per month

I track the hours that I have worked on something in an Excel sheet (actually Google Spreadsheet, but semantics). This is tracked in the following format: Date | Start (time) | End (time) | ...
1
vote
0answers
36 views

Rails Calendar Generation Method

I have this helper method that generates an HTML calendar based on the current day: ...
3
votes
0answers
44 views

Convert date time string with non standard timezone offset in C#

I couldn't find a .NET date format type to handle dates in format I need to process, they sometimes have time zone offset with +/- prefix followed by 3 digits for the number of minutes timezone is ...
3
votes
2answers
81 views

Script to activate an alarm at a time in the future

I am making a flashlight plugin for macOS. Here is the main code, plugin.py, the method results gets called first and is passed ...
2
votes
3answers
127 views
6
votes
3answers
100 views

Weekday+day validation

The string I'd like to check is something like "abcSun24def". If any valid "xxxyy" (xxx = weekday and yy = day) is found, return the position inside the string. If "xxxyy" is not found, return -1. ...
1
vote
2answers
83 views

time_t to string

...
22
votes
5answers
2k views

Extensible code to support different HR rules

Recently, I got challenged to code with following bullet points: Extensible code to support different annual leave rules for HR departments Maintainable code to add/change the existing rules ...
8
votes
1answer
94 views

Determine when a task will be completed

A friend of mine told me he had the following exercises at his interview : You need to determine when a task will be completed if you are given : A date when the task is started The ...
1
vote
1answer
38 views

The number of seconds between 2 Dates

I have this method in Java: ...
5
votes
1answer
63 views

Converting a 12h clock to 24h clock

I started picking up Rust on my free time, and I'm curious about what style errors have I made and where should I improve as a programmer. The problem is from HackerRank and very simple: there is a ...
2
votes
1answer
53 views

Messy Date Formatting

There can only be better ways to do this? create strings for today's directory strDate is yesterday's date in format ddmmyyyy (e.g. 08122016) ...
3
votes
2answers
107 views

Digital Clock in Java

I'm just looking for some feedback: ...
2
votes
1answer
46 views

A class to store the number of seconds since midnight

The purpose of this code is to to implement the time as the number of seconds since midnight. The class should have one data field (an int with the number of seconds since midnight) instead of three....
3
votes
1answer
43 views

Random timestamp within last 3 relative years

I'm trying to generate a random time between now and 3 years ago. To my knowledge, Go doesn't have a random(min,max) feature in either ...
3
votes
0answers
28 views

Perl nagios plugin to query an api, obtain date from json, and determine if the date is within thresholds

This is an update of Using an API to obtain JSON data and get the date string and determine if data is stale This is a nagios check that will use an API URL, get JSON data, flatten the data into a ...
4
votes
1answer
36 views

Tabulate schedule/calendar for database import

My company uses an Excel workbook to schedule our manufacturing jobs. I'm attempting to log job positions on the schedule and import them into Access on a semi-regular basis (twice a month?). This ...
6
votes
2answers
57 views

Using an API to obtain JSON data and get the date string and determine if data is stale

This is a nagios check that will use an API URL, get JSON data, flatten the data into a usable perl hash, and ultimately obtain a date string. Once the date is obtained, it should recognize the ...
4
votes
3answers
99 views

Computing the name of the month

I created the following program that transforms a numerical month into the corresponding textual month. I initially calculated the starPoint and ...
5
votes
1answer
54 views

jQuery Double Timepicker

I have one year of JavaScript/jQuery experience but I feel a bit messy in my code. The point is that I make some code that works but I feel that it can be improved like hell. I look for that, but even ...
4
votes
1answer
109 views

ISO 8601 dates & times format into a more human readable format

I wrote from the ground up this small piece of code which transforms dates and times formatted in ISO 8601 format into a more human readable format, client-side. The main goal is that you can create ...
4
votes
1answer
46 views

Getting the three next days

I'm simply getting the 3 future days from an array of objects based on the current day to display for a weather component. This is the first time I've attempted using ES6 and it's features so please ...
3
votes
2answers
37 views

Ensure continuous date range

I have two arrays dates = ["20161010","20161013"] values = [5,3] which represent dates and a view count. To display them in a graph, I also need the values ...
3
votes
1answer
64 views

Blow the fuse if threshold exceeded

While implementing the Retry & Breaker patterns I decided that the Breaker does more then it should so I extracted two responsibilities into their own classes. Here they are. I stripped out the <...
3
votes
3answers
68 views

Constructor for a Time object

I am trying to write a constructor method that takes dd, hh, mm and ...
5
votes
3answers
102 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 ...
0
votes
2answers
65 views

Find every 6 hours from now

I need to find a set of hours, starting from now, every 6 hours. So if now is midnight, I want [ 0, 6, 12, 18 ]. If now is 15h (3pm), I want ...
14
votes
1answer
206 views

How many days to Go?

Here's my first serious attempt at writing Go code. This program counts the number of days until a certain date and displays that in the system tray. To do that, it first reads the target date from ...
6
votes
1answer
99 views

Method to return date ranges of 1 year

I made a method that takes 2 DateTimes as a parameter, a startDate and a stopDate. The ...
4
votes
3answers
143 views

Describing a date interval as text

...
1
vote
0answers
24 views

Select to pick quarter (date)

An includable select to pick the first day of quarter: ...
0
votes
1answer
48 views

Displaying a timetable

The following code displays a Timetable, but the code needs too long finish the whole process. ...
2
votes
1answer
102 views

JavaScript calendar

This is implementation of a Datepicker by our outsource colleagues. I want to get an objective criticism of code style and approaches used. I see: Global variables with popular names Styles inside ...
0
votes
1answer
33 views

Remove dates from a list which have already past and add a buffer of x amount of days

Is there a more efficient/performant way to accomplish this with vanilla js (no libs please) as the looping is slow? Also, how can I make it more flexible, so the HTML option values can vary a little, ...
3
votes
1answer
74 views

Outputting years with no repeated digits

I'm working through a course now, and was tasked with the following: Write a function, no_repeats(year_start, year_end), which takes a range of years and outputs ...
9
votes
3answers
263 views

Verify if meeting datetime ranges overlap in an IEnumerable list of meetings

I have an assignment where I need to find out if any of the meetings in a list of meeting class object have overlapping datetime ranges. What I have so far is this: ...
1
vote
2answers
83 views

Taking some JSON data, converting the date format and calculating a user average

I'm originally a Java developer taking a stab at some Scala development. One of the main reasons I'm posting is because I know that in Scala you can write your code in a Java (OOP) way and it will run ...
3
votes
1answer
33 views

Python date compression

I m making a script to store date information in the smallest size in bits (I don't mind of the actually memory use in the program / runtime) ...
5
votes
4answers
591 views

Day of year calculation method

The exercise I wanted to solve is from here. Copying from that page: ...
4
votes
2answers
75 views

Determining the number of days in a month

Overall logic: determine number of days in a month. Loop through table (wsUploadTable) and increment value if condition is met. Loop to next day in month and repeat....