Smarter ToDos with Kotlin

 1 year ago
source link: https://kaushik.page/blog/smarter-todos-with-kotlin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Smarter ToDos with Kotlin »

Kaushik Gopal

Checkout this quick blog post I wrote for my company, tweaking the existing Kotlin TODO to work towards our requirements.

While I don’t think this solution is a panacea for all your missing code snippets, I have found some luck with this method, in adding accountability for those PR review feedback comments you say you’ll get to, but conveniently forget :)

Here’s a bonus if you’re reading this article from here:

 * @param month - regular month (so 3 = March)
fun ISDate(
    day: Int? = null,
    month: Int? = null,
    year: Int? = null,
    hour: Int? = null,
    minute: Int? = null,
    second: Int? = null,
    date: Date? = null
): Date = Date().apply {

    val cal = Calendar.getInstance()

    date?.let { cal.time = it }
    day?.let { cal.set(Calendar.DAY_OF_MONTH, it) }
    month?.let { cal.set(Calendar.MONTH, it - 1) }
    year?.let { cal.set(Calendar.YEAR, it) }
    hour?.let { cal.set(Calendar.HOUR_OF_DAY, it) }
    minute?.let { cal.set(Calendar.MINUTE, it) }
    second?.let { cal.set(Calendar.SECOND, it) }

    return cal.time

It’s a pretty straightforward date builder with minor tweaks (for e.g. 3 = March cause what are we, Monsters ?).

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK