0

So I have a list of data (let's say of yesterday's date) with dateless timestamps that go from 23:45 all the way to 00:00 inclusive, meaning that the 00:00 data is also included, but obviously those ones are of a different date. The file where this data is contained doesn't store any date information on anywhere but the filename itself, and I need to be able to output these timestamps along with their correct dates.

so e.g. if I have

23:58
23:59
00:00

then I should be able to output

14/09/2020 23:58
14/09/2020 23:59
15/09/2020 00:00

How would I go about checking if the date has advanced just from the clock time with only yesterday's date at hand?

I should note that this list isn't perfectly sorted, so I will still occasionally find 23:59 stamps inbetween the 00:00 ones, for example.

This is my first question on SO, and I've not been able to find existing answers to this, so I hope this is ok to ask.

Excal
  • 1
  • You will need to sort the data first, then you could simply iterate the list and check for a jump from 23:XX to 00:XX using an if statement `if(previousTime.startsWith(23) && currentTime.startsWith(00)) { date = new ..... }` and you can simply imcriment the date. – sorifiend Sep 15 '20 at 03:44
  • 1
    I'm puzzled by the fact that you have a file named with a date an dateless time lines inside and you think that any of those will belong to another date. I mean, a day hast 24 hours and that (in a 24 hours format) goes from 00:00 to 23:59. Being 00:00 midnight, 00:01 one minute past midnight, 12:00 will be noon and then 23:59 will be one minute before midnight. If all you have is a dateless time there is no way to know the date. But because they are in a dated file, I'd say they all belong to that day. – drkblog Sep 15 '20 at 03:54
  • @drkblog maybe I should clarify more heh, these are timestamps generated from a mobile phone, and represents a user activity around the late night hours. so the date indeed HAS changed at the 00:00 mark – Excal Sep 15 '20 at 04:19
  • @sorifiend this is the naive answer, but since I'm dealing with practically hundred-thousands of these and in a large-scale system too, i would not want to sort it just yet. at least not at this stage. – Excal Sep 15 '20 at 04:21
  • 1
    @Excal if you know for a fact that these are all around midnight then just define "around" in minutes or hours. For instance, you could know that it's less than an hour before or after midnight and the file won't have any time before 23:00 or after 00:59. Then it's quite easy. For anything starting 23:xx use the date and for anything 00:xx use the date plus one day. – drkblog Sep 15 '20 at 04:32

0 Answers0