Skip to content

Conversation

@gajosu
Copy link
Contributor

@gajosu gajosu commented Jun 5, 2024

This pull request introduces the capability to specify a custom date column when using the range method. This enhancement provides greater flexibility in metric calculations, allowing users to filter and calculate metrics based on custom date fields.

Changes:

  • Metric.php: Added a new method dateColumn(string $dateColumn) to allow the specification of a custom date column.
  • Modified the getDateColumn method to return the custom date column if specified, defaulting to the model's created_at column otherwise.
  • Updated existing methods to ensure compatibility with the new custom date column feature.

Tests:

  • Added a new test CustomDateColumnTest.php to verify the functionality of using a custom date column for metric calculations.
    • This test checks the correct counting of users based on the email_verified_at column within a specified date range.
    • Ensured that the growth rate calculations are accurate when using the custom date column.

Impact:

  • This feature maintains backward compatibility, as it defaults to using the model's created_at column if no custom date column is specified.
  • Provides enhanced flexibility for users needing to perform metric calculations based on various date fields within their models.

Example Usage:

$data = Value::make(User::class)
    ->dateColumn('email_verified_at') // Specify custom date column
    ->range(15) // Define the date range
    ->count();

@gajosu gajosu force-pushed the add-custom-date-column branch from 98ed2b0 to 4a4dc95 Compare June 5, 2024 21:06
@sakanjo sakanjo merged commit 9ab5d75 into sakanjo:master Jun 7, 2024
@sakanjo
Copy link
Owner

sakanjo commented Jun 7, 2024

Thanks for the implementation!

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