Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeAgo doubtful result #243

Open
Austinate opened this issue Jan 18, 2018 · 3 comments
Open

timeAgo doubtful result #243

Austinate opened this issue Jan 18, 2018 · 3 comments

Comments

@Austinate
Copy link

Hi! First of all — thanks for such an awesome project!

I've faced an issue where given date:

2018-01-16 12:18:37 +0000
  - timeIntervalSinceReferenceDate : 537797917.0

with timeAgoSinceNow produces this result:

23 hours ago

Now is:

2018-01-18 11:41:16 +0000
  - timeIntervalSinceReferenceDate : 537968476.40061295

And in components calculated inside public func timeAgo(since date:Date, numericDates: Bool = false, numericTimes: Bool = false) -> String function i see this:

▿ year: 0 month: 0 day: 1 hour: 23 minute: 29 second: 49 weekOfYear: 0 isLeapMonth: false 
  - year : 0
  - month : 0
  - day : 1
  - hour : 23
  - minute : 29
  - second : 49
  - weekOfYear : 0
  - isLeapMonth : false

So i'm a bit confused, should timeAgo be represented as 1 day 23 hours ago or even 2 days ago? Is this an expected behavior or this is a bug?

Would appreciate any help, thanks!

@Austinate Austinate changed the title timeAgo doubtful result. timeAgo doubtful result Jan 18, 2018
@agordeev
Copy link

agordeev commented Jan 29, 2018

I'm having the same issue.

Looks like the current date doesn't fall into this condition:

let isYesterday = yesterday.day == self.day
...
else if (isYesterday) {
....
}

In my case self is 2018-01-27 05:09:44 +0000 and yesterday is 2018-01-28 04:56:49 +0000

@UberJason
Copy link
Contributor

UberJason commented Apr 6, 2018

+1. Looking at the code, it defines yesterday as date.subtract(1.day):

let yesterday = date.subtract(1.days)
let isYesterday = yesterday.day == self.day

But I think it should actually be defining yesterday as the latest date minus 1 day, like this:

let yesterday = latest.subtract(1.days)
let isYesterday = yesterday.day == earliest.day

At least for me, when I made that change, stuff started working correctly.

I'll be submitting a PR shortly - hope @MatthewYork's recent resurgence in activity on this library means he'll be amenable to it!

This was referenced Apr 6, 2018
@BrentMifsud
Copy link

BrentMifsud commented Jul 9, 2021

yep ive noticed the same problem. some sample data:

Test Case:

let oldEpoch = 1625693136.000 // Jul 7, 2021 5:25 PM
let currentEpoch = 1625862719.98203 // Jul 9, 2021 4:31 PM

let oldDate = Date(timeIntervalSince1970: oldEpoch)
let newDate = Date(timeIntervalSince1970: currentEpoch)

print(oldDate.timeAgo(since: newDate)) // prints 23 hours

am I losing my mind? Shouldn't it be 1 day 23 hours?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants