Skip to main content

Interval Calculations in EasyAF

The EasyAF library provides a powerful and flexible system for handling time-based calculations through its Interval class hierarchy. This system enables you to work with frequencies, rates, and monetary amounts across different time periods with automatic conversion capabilities.

Core Concepts

Base Interval Class

The foundation of the system is the Interval<T> class, which represents frequency - how often something occurs over time. The key insight is that an interval represents “time per occurrence,” not “occurrences per time.”

Key Properties

  • Value: Always represents a time duration (e.g., 1.5 hours, 3 days, 2 weeks)
  • Type: The time unit for the Value (Hours, Days, Weeks, Months, Years)

Method Types

The interval classes provide two distinct types of calculation methods:
  1. *Per methods (inherited)**: Calculate interval frequency - how many intervals fit in a time period
  2. Specialized rate methods: Calculate total amounts for derived classes (money, ratios, percentages)

Interval Types

1. Base Interval Class

Calculates pure frequency - how many intervals occur within different time periods.

2. MoneyInterval Class

Represents financial amounts that occur at regular intervals. Unlike other derived classes, MoneyInterval overrides the base methods to directly return monetary amounts.

MoneyInterval ToString Methods

3. RatioInterval Class

Combines base interval calculations with ratio multiplication. Provides both inherited frequency methods and new ratio calculation methods.

RatioInterval Use Cases

4. PercentageInterval Class

Similar to RatioInterval but designed specifically for percentage-based calculations. Uses Rate property and provides RatePer* methods.

PercentageInterval Use Cases

Advanced Examples

Complex Financial Scenarios

Quantity-Based Calculations

The new overloaded methods allow you to directly calculate results for specific quantities:

Widget Production with Materials

Lead Conversion with Customer Quantities

Interest Calculations with Principal Amounts

Performance and Conversion Tracking

Interest and Growth Calculations

Method Reference

Base Interval Methods (All Classes)

These methods calculate frequency - how many intervals fit within the specified time period:
  • PerMinute() - Intervals per minute
  • PerHour() - Intervals per hour
  • PerDay() - Intervals per day
  • PerWeek() - Intervals per week
  • PerMonth() - Intervals per month
  • PerYear() - Intervals per year
NEW: Quantity-based overloads:
  • PerMinute(decimal quantity) - Total output per minute for given quantity
  • PerHour(decimal quantity) - Total output per hour for given quantity
  • PerDay(decimal quantity) - Total output per day for given quantity
  • PerWeek(decimal quantity) - Total output per week for given quantity
  • PerMonth(decimal quantity) - Total output per month for given quantity
  • PerYear(decimal quantity) - Total output per year for given quantity

MoneyInterval Methods

MoneyInterval overrides the base methods to return monetary amounts:
  • PerMinute() - Dollars per minute
  • PerHour() - Dollars per hour
  • PerDay() - Dollars per day
  • PerWeek() - Dollars per week
  • PerMonth() - Dollars per month
  • PerYear() - Dollars per year
NEW: Quantity-based overloads (e.g., hours worked, units sold):
  • PerMinute(decimal quantity) - Total earnings per minute for given quantity
  • PerHour(decimal quantity) - Total earnings per hour for given quantity
  • PerDay(decimal quantity) - Total earnings per day for given quantity
  • PerWeek(decimal quantity) - Total earnings per week for given quantity
  • PerMonth(decimal quantity) - Total earnings per month for given quantity
  • PerYear(decimal quantity) - Total earnings per year for given quantity

RatioInterval Methods

RatioInterval provides both inherited frequency methods and new ratio methods: Frequency methods (inherited):
  • PerMinute(), PerHour(), PerDay(), etc. - Number of intervals per time period
  • PerMinute(decimal quantity), PerHour(decimal quantity), etc. - Total output for given quantity
Ratio methods:
  • RatioPerMinute() - Total ratio per minute (intervals × ratio)
  • RatioPerHour() - Total ratio per hour
  • RatioPerDay() - Total ratio per day
  • RatioPerWeek() - Total ratio per week
  • RatioPerMonth() - Total ratio per month
  • RatioPerYear() - Total ratio per year
NEW: Quantity-based ratio overloads:
  • RatioPerMinute(decimal quantity) - Total ratio applied to quantity per minute
  • RatioPerHour(decimal quantity) - Total ratio applied to quantity per hour
  • RatioPerDay(decimal quantity) - Total ratio applied to quantity per day
  • RatioPerWeek(decimal quantity) - Total ratio applied to quantity per week
  • RatioPerMonth(decimal quantity) - Total ratio applied to quantity per month
  • RatioPerYear(decimal quantity) - Total ratio applied to quantity per year

PercentageInterval Methods

PercentageInterval provides both inherited frequency methods and new rate methods: Frequency methods (inherited):
  • PerMinute(), PerHour(), PerDay(), etc. - Number of intervals per time period
  • PerMinute(decimal quantity), PerHour(decimal quantity), etc. - Total output for given quantity
Rate methods:
  • RatePerMinute() - Total rate per minute (intervals × rate)
  • RatePerHour() - Total rate per hour
  • RatePerDay() - Total rate per day
  • RatePerWeek() - Total rate per week
  • RatePerMonth() - Total rate per month
  • RatePerYear() - Total rate per year
NEW: Principal-based rate overloads:
  • RatePerMinute(decimal principal) - Total rate applied to principal per minute
  • RatePerHour(decimal principal) - Total rate applied to principal per hour
  • RatePerDay(decimal principal) - Total rate applied to principal per day
  • RatePerWeek(decimal principal) - Total rate applied to principal per week
  • RatePerMonth(decimal principal) - Total rate applied to principal per month
  • RatePerYear(decimal principal) - Total rate applied to principal per year

Time Conversion Constants

The system uses these conversion factors for calculations:
  • Minutes per hour: 60
  • Hours per day: 24
  • Days per week: 7
  • Days per month: 30.4375 (365.25 ÷ 12)
  • Days per year: 365.25
  • Weeks per month: 4.345 (30.4375 ÷ 7)
  • Months per year: 12

Best Practices

1. Choose the Right Class

  • Use Interval<T> for pure frequency calculations
  • Use MoneyInterval<T> for financial amounts where you want direct monetary results
  • Use RatioInterval<T> for general ratio/rate calculations where you need both frequency and rate methods
  • Use PercentageInterval<T> for percentage-based calculations

2. Understanding Method Behavior

3. Precision Considerations

All calculations return decimal values for maximum precision in financial and rate calculations. Be aware that some conversions may result in repeating decimals.

4. Validation

Always validate input values:
This interval system provides a robust foundation for time-based calculations across financial, performance, and analytical scenarios in your applications.