linkedin / linkedin/ambry

Use java TimeUnit enum instead of raw multiplication for time unit conversions.

Open
#597 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement newbie
Dominant language
Java
Stars
1.8k
Forks
298
Avg merge
21h 43m
Merged PRs (30d)
9

Description

In many parts of our codebase, we use constants in `com.github.ambry.utils.Time` for conversions between different time units. This is prone to typos and overflow/underflow mistakes. We should prefer using the java TimeUnit enum (https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html) to do these conversions. For example `seconds * Time.SecsPerMin * Time.MinsPerHour * Time.HoursPerDay` can be replaced with `TimeUnit.SECONDS.toDays(seconds)`.

We should check over existing parts of our codebase and fix this as we encounter usages of those constants.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the codebase for usages of constants in com.github.ambry.utils.Time, then inspect each conversion involving raw multiplication. Replace applicable conversions with java.util.concurrent.TimeUnit methods and verify that the converted values preserve the intended units without overflow or underflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.