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
70 views

Article date extractor

I am quite new to Rust and this is my first library written in it. It's an article date extractor heavily inspired by the original Python library as well as its Haskell port. It is fairly small and ...
5
votes
1answer
43 views

Difference between API time and server time

I'm using the openweathermap API to get weather forecast data. I want to make sure that the forecast values are at minimum 2 hours in the future. The API is providing the forecast in 3 hour steps, so ...
7
votes
1answer
33 views

Function that returns index of Forex candle according opening hours (weekly session)

The output of the function is as desired. When Forex opens at Sunday, first candle is annotated with 1 and the number increments with every new candle, till weekend, when the imaginary counter is ...
4
votes
3answers
63 views

Specifying the Kind on DateTime

I've got a system and every object in my system has a base class with property: DateTime DateCreated In the constructor for the base class I set the ...
4
votes
0answers
39 views

Calculating parking and charging statistics for a car-sharing service

I am looking for help in designing my code more efficiently and also in keeping the slope of my personal learning curve steep: For a research project I have per car data from two different car ...
3
votes
0answers
77 views

Implementing a week schedule class in C#

Requirements A week schedule class .NET framework has DateTime struct, but I want a general week schedule class that involves day of week instead of date. For example, a shop has open hours from 9:...
8
votes
3answers
1k views

Show time in format yyyy-MM-ddThh:mm:ss.SSS

My requirement is to convert a time (long) to a String with this date format: yyyy-MM-ddThh:mm:ss.SSS For instance: 2017-03-07T03:52:31.298 My implementation: ...
1
vote
0answers
51 views

getDayOfTheWeek function, without using built-in date libraries

I have an assignment to create a method to retrieve the proper day of the week for any given date, without using the Java calendar. After countless hours of trying to implement the algorithm in the ...
4
votes
3answers
49 views

Get first DateTime by given weekdays and a starttime

At work there is an input-system where customers are able to specify weekdays and a starting time for an event. The weekdays are integers in the range from 1 (Monday) to 7 (Sunday). After the customer ...
2
votes
0answers
58 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. <...
5
votes
0answers
24 views

Coalesce consecutive failures in a DataFrame of hourly sensor readings

I have a PANDAS DataFrame that contains sensor data that is recorded every hour (sample included below). It is important to note that every hour is not necessarily in the dataframe, as sometimes the ...
1
vote
1answer
55 views

Round fractional seconds of MySQL Time

I've written a method to round a MySQL Time to two decimal places. Here's some examples: ...
3
votes
4answers
85 views

JavaScript clock

I am trying to build a clock. You can see the working code here. However, I feel like I can do much better in the JavaScript code. ...
3
votes
3answers
132 views

Function to check if a date is correct

I have a method that checks if a date is correct or not, which returns a boolean if it is or not. In the method, I first check the format, then the date by using the function ...
4
votes
1answer
54 views

Optimize calculation for the amount of time between when a value changes in Pandas

I have some sensor data that contains timestamps from when a machine is turned on and an indicator variable showing whether or not the machine is actively running. The data is mostly recorded every ...
0
votes
0answers
36 views

C# Regex to match UTC dates

Made the following regex strings to match for typical UTC dates. I'd appreciate it if you guys can let me know if it seems fine and not too lengthy. ...
2
votes
1answer
46 views

Array of date by each week

I have two dates, example : date1 = "4-02-2017".to_date date2 = "4-02-2017".to_date + 29 I try to get array of date by each week with this : ...
3
votes
2answers
76 views

Simple timer checking class

This is a simple class that runs a timer every 10 seconds to update the title with some information like how long the application has been up, depending on the datetime that is set in another class ...
2
votes
2answers
69 views

Rounding a time to its lowest quarter-hour

I calculate the lowest quarter-hour using the following code: ...
-1
votes
2answers
141 views

Interpret YYYYMMDD as the nth day of the year [closed]

I am provided a bunch of dates in the format (YYYYMMDD) such as: date='20170503' My goal is to convert that date into the ...
4
votes
0answers
49 views

Method that gets the date from a file according to the name of the client

I have in this class bellow, a method that gets the date from a file according to the name of the client. For each client, the method to extract the date is different. I want to use heritage or any ...
7
votes
1answer
80 views

Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
-1
votes
1answer
63 views

AngularJS calendar directive

Is adding CSS to template via <style> the right approach? How should I structure the application? Plunker link to the code ...
3
votes
2answers
66 views

Sum hours worked depending on day type

A while ago I posted this question about finding the Date in Range, where I explained I have a spreadsheet to control my shift hours and was interesting in improving one of my functions. I got ...
4
votes
4answers
362 views

Extension method to retrieve list of days in the current week

I want to get all days of the current week (from Monday to Sunday) with a custom time. To do this, I have written an extension method for TimeSpan: ...
1
vote
1answer
63 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 ...
3
votes
2answers
264 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
43 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
64 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
96 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
101 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
64 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 ...
4
votes
3answers
222 views

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

I would like to improve the following code: ...
4
votes
2answers
89 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
96 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
75 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
48 views

Rails Calendar Generation Method

I have this helper method that generates an HTML calendar based on the current day: ...
3
votes
0answers
66 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
96 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
164 views
6
votes
3answers
104 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
185 views

time_t to string

...
23
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
100 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
41 views

The number of seconds between 2 Dates

I have this method in Java: ...
5
votes
1answer
66 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
61 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
164 views

Digital Clock in Java

I'm just looking for some feedback: ...
2
votes
1answer
77 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
45 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 ...