DEV Community

Cover image for Day 45. Time manipulation
Kiolk
Kiolk

Posted on

Day 45. Time manipulation

What I did:

I spent today fixing the issue of sending time as a request parameter. The issue wasn't with sending time, but with calculating a specific time in the past. I use the kotlinx.datetime package for manipulating dates. My final solution looks like this:

fun SortingType.toTime(): Instant? {
    val currentInstant: Instant = Clock.System.now()

    return when (this) {
        SortingType.Infinity -> currentInstant.minus(365.toDuration(DurationUnit.DAYS) * YEARS_AGO_FOR_INFINITY)
        SortingType.Month -> currentInstant.minus(30.toDuration(DurationUnit.DAYS))
        SortingType.Week -> currentInstant.minus(7.toDuration(DurationUnit.DAYS))
        SortingType.Year -> currentInstant.minus(365.toDuration(DurationUnit.DAYS))
        else -> null
    }
}
Enter fullscreen mode Exit fullscreen mode

I spent some time on refactoring code and extracting methods and constants. 
I also found some interesting information in a comment on the Coderabbitai PR.  I had been wondering about the strange parameter name tag_names[] in the API call. Why does this name have square brackets? The answer is that the backend can accept multiple parameters with the same name. It is how arrays can be sent.
Coderabbitai
What I will do:

If you want to join the project, just leave a comment here, or write a message in LinkedIn.

What help I'm looking for:

Designer (create design of application in Figma)
Android/KMM developer
Any other help related to the project.

My timeline:

Day 1. Deep breath and dive
Day 2. Networking layer.
Day 3. Loading of articles.
Day 4. ArticleItem.
Day 5. Localization.
Day 6. Work on Sunday.
Day 7. First week.
Day 8. Enjoying coding.
Day 9. Expect/actual.
Day 10. TODOs.
Day 11. Friday evening.
Day 12. Frustration.
Day 13. Blocker
Day 14. Monday
Day 15. Reactions
Day 16. Feed
Day 17. stringWithFormat
Day 18. Comment
Day 19. 1 percent
Day 20. A bit of progress
Day 21. Pagination
Day 22. Lottie animation
Day 23. Sorting of articles
Day 24. Step by step
Day 25. Broken endpoint?
Day 26. After party
Day 27. Burnout
Day 28. Opportunity for growth
Day 29. Hard work
Day 30. Old code
Day 31. Technical debt
Day 32. API calls
Day 33. Generic response
Day 34. Response
Day 35. Coderabbit
Day 36. What is the power of Pull Request?
Day 37. Search challenge
Day 38. Search items
Day 39. A party
Day 40. Fixing UI
Day 41. Surpassed record
Day 42. Monday
Day 43. Composition
Day 44. Timestamp

You can find more useful content on my LinkedIn page, on X, in Medium or Mastodon.

See you tomorrow. 

Top comments (0)