Skip to content

feat: add xtime.FormatDuration and xtime.ParseDuration #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 22, 2025

Conversation

KimNorgaard
Copy link
Contributor

This adds an xtime package with functions for formatting and parsing durations.

@KimNorgaard KimNorgaard requested a review from a team as a code owner April 14, 2025 11:00
@KimNorgaard KimNorgaard requested a review from Copilot April 22, 2025 09:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the new xtime package to support human‐readable duration parsing and formatting. Key changes include:

  • Implementation of ParseDuration and FormatDuration functions along with supporting helper functions.
  • Extensive test coverage for tokenization, parsing, formatting, and rounding behaviors.
  • Updated documentation and README to include xtime functionality.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
xtime/tokenize_test.go Adds tests for the tokenization of duration strings.
xtime/parse_test.go Provides test cases for parsing durations with various formats.
xtime/parse.go Implements the ParseDuration function and related error handling.
xtime/duration_test.go Contains comprehensive tests for duration formatting and rounding.
xtime/duration.go Implements FormatDuration and supporting formatting options.
xtime/doc.go Documents the xtime package and illustrates formatting/parsing usage.
xtime/const.go Defines the float64Size constant for float parsing.
xtime/clean_test.go Tests the clean function used in input preprocessing.
README.md Updates the README to include information about the new xtime package.
Comments suppressed due to low confidence (2)

xtime/const.go:4

  • [nitpick] Consider renaming 'float64Size' to a more descriptive name such as 'floatBitSize' to clarify that it represents the bit size used in float parsing.
float64Size = 64

README.md:14

  • [nitpick] Consider rephrasing for clarity, for example: 'The packages are dependency-free, meaning they must not use any external dependencies unless explicitly listed.'
The packages are dependency free meaning packages added to this module must not use any external dependencies unless listed below.

@KimNorgaard KimNorgaard requested a review from Copilot April 22, 2025 09:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an xtime package that provides functions for formatting and parsing durations.

  • Introduces functions for tokenizing, parsing, and formatting human-readable durations.
  • Includes comprehensive tests covering edge cases and rounding behavior.
  • Updates documentation and README to reflect the new xtime package.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
xtime/tokenize_test.go Tests for the tokenize function covering various cases.
xtime/parse_test.go Tests for ParseDuration with valid and invalid inputs.
xtime/parse.go Implements duration parsing using tokenization and cleaning.
xtime/duration_test.go Tests for FormatDuration and related helper functions.
xtime/duration.go Implements duration formatting and unit definitions.
xtime/doc.go Adds documentation for the xtime package functionality.
xtime/const.go Provides a helper constant for float precision.
xtime/clean_test.go Tests for the clean function used by ParseDuration.
README.md Updates module documentation to include the new xtime package.

Co-authored-by: Copilot <[email protected]>
@KimNorgaard KimNorgaard requested a review from Copilot April 22, 2025 09:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new xtime package that provides functions for parsing and formatting durations. Key changes include:

  • Adding ParseDuration and its supporting error type and tokenization logic.
  • Implementing FormatDuration with customizable formatting options (styles, rounding, and unit limits).
  • Creating comprehensive tests and documentation for the new package.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
xtime/tokenize_test.go Tests for tokenizing duration strings are added.
xtime/parse_test.go Extensive test cases covering valid and invalid duration inputs.
xtime/parse.go Implementation of the duration parsing logic and error handling.
xtime/duration_test.go Comprehensive tests for duration formatting options.
xtime/duration.go Implements FormatDuration with various options and rounding.
xtime/doc.go Documentation for the xtime package and its functionality.
xtime/const.go Definition for constants used across the package.
xtime/clean_test.go Tests for the clean() helper function.
README.md Updated project documentation to include xtime functionality.

ChBLA
ChBLA previously approved these changes Apr 22, 2025
Copy link
Contributor

@ChBLA ChBLA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few questions

KimNorgaard and others added 7 commits April 22, 2025 13:06
This removed the version package. Having a version.First does not justify
a package by itself. The function is not specific to versions and has been
recreated as xstrings.Coalesce(). No need to deprecate as it is only used in one
place.
@KimNorgaard KimNorgaard requested a review from ChBLA April 22, 2025 11:20
@KimNorgaard KimNorgaard merged commit 0b47aec into main Apr 22, 2025
1 check passed
@KimNorgaard KimNorgaard deleted the feat/xtime-duration branch April 22, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants