Home Projects Portfolio Dashboard Export PDF Log in
PHP PHPUnit

Automating Timeline Calculations for Professional CVs

In our landing project, we recently focused on improving the readability of professional credentials by automating the calculation of durations for work experience, education, and skills. Rather than manually updating date strings, we wanted a system that could dynamically compute and display how much time has passed for any given period.

The Challenge: Dynamic Time Parsing

Users often enter their professional history in varied formats, such as "Jan 2020 – Present" or "2020 – 2023". Calculating the duration between these dates requires a robust helper capable of parsing natural language strings into comparable objects. By introducing a dedicated CvDurationFormatter, we can keep our template logic clean while ensuring consistent formatting across both HTML views and generated DOCX files.

Implementation Strategy

We implemented a formatter that calculates the difference and applies a consistent display rule: if the period is longer than three months, it displays the duration; otherwise, it stays silent to avoid cluttering short-term experiences.

class CvDurationFormatter
{
    public function format(string $period): string
    {
        $diff = $this->parsePeriodToInterval($period);
        
        if ($diff->months < 3 && $diff->years === 0) {
            return '';
        }

        return $this->getReadableString($diff);
    }
}

This helper abstracts the complex logic of date arithmetic away from the UI components. By using PHPUnit for testing, we ensure that the parser correctly handles edge cases, such as leap years or end-of-year transitions, without breaking the visual integrity of our CV documents.

The Lesson

Adding this layer of automation transforms static, manual strings into dynamic data. It ensures that your experience section is always up-to-date and reduces the maintenance overhead every time a user updates their profile. By treating data presentation as a distinct service, we make our codebase more resilient to changes in UI requirements.

Actionable Takeaway

Look for repetitive data formatting in your templates and extract it into dedicated helper classes. Writing a few targeted tests for these formatters will save you hours of debugging UI edge cases in the long run.


Generated with Gitvlg.com

Automating Timeline Calculations for Professional CVs
Germanwithpants

Germanwithpants

Author

Share: