We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

47

Ask yourself why you need such a variable in the first place. Most likely, you are lying about your data: whenever you need an "end of time" variable, you are not referring to the actual end of time; rather you are expressing things like "there is no upper bound for this date", "this event continues indefinitely", or similar. The correct solution, then, is ...


31

The best place to start is probably the "design philosophy" section of the user guide. But to lay out specific differences between Noda Time and Joda Time: Noda Time keeps much more of its code internal. This makes it less flexible, in that you actually can't create your own calendar system - but also means the API is simpler both to learn and use. Nullity ...


18

It can be a big factor during development: if your platform does not support changing code in a running application, then the startup time becomes part of your feedback cycle, and there, even 30 seconds are painful and a threat to productivity. For the production environment, it really does not matter; either a little downtime is acceptable and 5 minutes ...


17

As an industry we have been notoriously short-sighted and arbitrary in the pursuit of saving a few bytes e.g. 31 Dec 99 January 19 2038 T + 50 years, when hopefully all systems I've been involved in have become defunct or been replaced (or I'm dead, whichever comes first). IMHO the best bet is to stay with a appropriate, mainstream level of abstraction on '...


17

It's because it would break every build system like make, maven, gradle, etc. that depends on file modification times to know what needs to be rebuilt. If a git checkout or a git pull pulls in commits that are older than the last executable you built, it would give those files an older timestamp. make therefore won't detect them as an updated dependency, ...


16

You should return an absolute point in time, then anyone can localize that timestamp as needed. By "absolute timestamp" I mean either a UNIX timestamp or a human readable timestamp which includes the timezone in one of the standardized ISO formats, e.g. "2007-04-05T14:30Z". This can trivially be converted to a local timezone by the client as necessary. If ...


16

Time Complexity (Big-O notation) does not measure performance of an algorithm. Instead, it categorizes how an algorithm's resource use scales with input size. This allows us to compare two algorithms with a judgement such as “for some sufficiently big input, algorithm A will always be faster than algorithm B”. We can do this judgement without even ...


15

Include all the start and end points (in time) of the Jobs in an array (this creates 2*N elements (1 for start 1 for end)) sort the array ordering by the timestamp of the event, then iterate over the (2*N) elements as follows: for each element X do if(X.type == start) counter++ else counter-- ans=max(ans, counter); end Complexity: O(n.log(...


15

It is obviously open/closed interval. How else do you want to create continuous interval of all days and still be able to account for mili/microseconds? And it is obviously 24 hour long. That single second between 23:59:59 and 00:00:00 still counts.


14

I'd go with UTC. It has several advantages: It's universal and doesn't change with daylight saving time. It won't change if your server changes timezone. It won't change if authors change timezone. There are standard conversions between UTC and local time zones. Despite the problems it sometimes causes (confusion over the "day") it can be explained and is ...


13

Let's take today for example, the day started on 13 Dec 2012 00:00:00 and according to (all) date-time implementations it will end on 14 Dec 2012 00:00:00 No. By convention the day starts at 00:00:00 and end at 23:59:59 (well 23:59:59.999 if you go down to milliseconds). Time is continuous, but we have to represent it by discrete values (no matter how "...


12

Instead of calling System.currentTimeMillis() directly, I would wrap that in your own class and inject it into your code dynamically. What this gives you is the ability to mock your wrapper object to return a fixed time in the context of tests. This means that your test code will never actually call System.currentTimeMillis(), but rather get a fixed time to ...


12

You should DEFINITELY arrange to mock-out the system clock. I've worked in C++, and either I make the object take a 'clock interface' object, or I use an internal interface or function pointer inside the class that I then replace when doing test code. I've actually had experience with NOT mocking out the system clock and believe me when I tell you - it ...


11

I think it's safe to assume there is a similar "starting date" in other languages so I guess the specific implementation in Java doesn't matter. Pretty much all computers use this or a similar variation of Unix time. How is the time calculation performed by the computer? How does it know exactly how many milliseconds have passed from that given "...


11

In theory, yes file size can affect the running time of a program. However, the affect it has is probably so insignificant you should never have to worry about it. There are a few reasons for this: Compilers/interpreters are very smart and would optimize the code to be as performant as possible. Your example would be a great candidate for dead code ...


10

I don't think you're going to gain much by storing all of your datetimes as longs. Every language I can think of has ways to convert dates to other formats (string, long) use the preferred format for your database. Store the dates in UTC. I think this makes sense for nearly every application, since many languages and APIs have a way to get Now() in UTC. ...


9

You have to be careful with this kind of distributed system. For example: imagine I have a triggering server in London and another in New York. If a Deep One cuts through the cable between them, London will think "NY's gone down, I have to take over", and NY will think "London's gone done, I have to take over"... and your application will be triggered twice. ...


9

There's actually quite a bit you can do to recover something close to the actual time of most of your events. Android gives you a few useful tools to work with, notably broadcast intents sent when the device completes a boot, when the system clock changes and when a shutdown is imminent. It also gives you a way to check the amount of real time that's ...


9

Not storing the end date and using the start date of a different record/row make each individual row hard to reason about. Querying gets harder. SQL Server 2012 introduced LEAD and LAG to help with these kinds of queries. Full explanation here. A short example for your case: SELECT StartDate, LEAD(StartDate) OVER (ORDER BY StartDate) as ...


8

It depends on the usage, but I'd probably say it's safest to convert to UTC then pass the ISO 8601 style string as you suggest. That way, it's human-readable, and you don't have to worry about different time zones, etc. While I was researching for an answer, I found an interesting answer on StackOverflow you might want to read: link. (edit) Also, if you'...


8

No. Usually a datetime is data type or data structure, as a means of storing moments in memory/disk. A timestamp is an individual record that indicates an instant in time that something took place, virtually always in the past. Often you could use a datetime to store a timestamp, but not all datetime records would be timestamps. The instant a vending ...


8

The core idea behind floating point numbers is that you have some number of bits for the mantissa, and then some number of bits to tell where the decimal point is, and of course a bit for the sign. Let us not get down into how that works in practice. Have a video. Have more videos. Here is the deal, around 0 we get a lot of precision, because we can place ...


8

You mentioned in the comments you're OK to compress the timestamp to 52 bits. Few other people mentioned you can negotiate smaller process Ids. I'm expanding on these ideas with one way to generate lock-free very high speed timestamps, not just machine-wide, but world-wide. That's because the processes don't share state apart from initial setup and thus ...


7

You probably want an algebraic data type with variant for infinite big date. Then define comparison, in which infinite variant will be always bigger than any other date. Example in Scala: sealed abstract class SmartTime extends Ordered[SmartTime] { x => def compare(y: SmartTime) = { x match { case ...


7

The usual practice is to set the servers to all keep their time updated using NTP. There are limitations to the accuracy when using NTP time syncing which means that you should only rely on the time stamp to give a general idea of when events occurred, which is likely to be good enough for identifying the set of events you are interested in. Timestamps are ...


6

We had the same problem in our project and we persisted all the time in database as UTC. The UTC time is converted to local timezone of the user when accessing / reading the data. This simplified our entire design.


6

Do not use System.currentTimeMillis(), but program everything using time against an interface returning time. During unit-testing, mock the interface, else you simply cannot test anything using time reliably. This also has the benefit that if you decide currentTimeMillis is not accurate enough, you can replace it with another method in one single spot and ...


6

That would depend on how you interpreted the date. If you use the date as though it were YYYY-MM-DD 00:00:00 (or any specific time) then you would probably want to take account of time zones. If you use the date as just on indication of the day then you probably don't. This is vague as without the context of what you are doing with the dates, it is just ...


6

Use the DST settings applicable to the timestamp. This will apply the correct conversion rules. For example if I use the current DST status a local time in January would be incorrectly converted, as I am currently in DST and January uses ST here. Most languages already have a function or method to do the conversion. Unless you have strong reasons to ...


6

The key to resolving your problem is to return a special object on the insertion of a element. When you move the real object in the heap, you update the position in this object. To call decrease-priority you pass this object so you can go right to the position in the heap and bubble up the element if necessary. In this way it's O(log(n)). In fact finding ...


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