Calendar.Component.day ignores calendar month differences
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- mobile-dev
Research direction
Start at the referenced mapping in Sources/SkipFoundation/DateComponents.swift and compare the Swift .day behavior with the java.util.Calendar field used there. Verify the Jan 1 to Feb 1 and 31-day examples, then confirm that dateComponents([.day], from:to:) reports the full elapsed day difference across month boundaries.
Written by the indexing model from the issue text.
Description
In Swift, this code shows a 31 day difference
let today = Date()
let future = Calendar.current.date(
byAdding: .day,
value: 31,
to: today
) ?? Date()
print(Calendar.current.dateComponents([.day], from: today, to: future).day ?? 0) // ~31 days
But when transpiled through Skip it only shows a 0 or 1 day difference between the two dates.
This is because this line in DateComponents.swift incorrectly maps the .day Swift case to java.util.Calendar.DAY_OF_MONTH, which only looks at "day of month" and ignores differences between months. Jan 1 and Feb 1 are treated the same.
Here's a workaround till this is fixed.
#if SKIP
let startDate = startDate(nocopy: true).toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
let endDate = endDate.kotlin(nocopy: true).toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
return ChronoUnit.DAYS.between(startDate, endDate).toInt()
#else
return Calendar.current.dateComponents([.day], from: startDate, to: endDate).day ?? 0
#endif
- Dominant language
- Swift
- Stars
- 17
- Forks
- 16
- Avg merge
- 1h 50m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from skiptools/skip-foundation
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
skiptools/skip-foundation#128 · 1 comment · 1 reaction ·
-
enhancement
skiptools/skip-foundation#120 · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
skiptools/skip-foundation#78 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
skiptools/skip-foundation#81 · 2 comments ·
-
URLCache Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
skiptools/skip-foundation#70 · 1 comment ·
All issues in skiptools/skip-foundation
Similar issues
-
tvOS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
skiptools/skip-fuse-ui#147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OneBusAway/onebusaway-ios#1438 · 1 reaction ·