Interval Calculations in EasyAF
The EasyAF library provides a powerful and flexible system for handling time-based calculations through itsInterval 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 theInterval<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:- *Per methods (inherited)**: Calculate interval frequency - how many intervals fit in a time period
- 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. UsesRate 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 minutePerHour()- Intervals per hourPerDay()- Intervals per dayPerWeek()- Intervals per weekPerMonth()- Intervals per monthPerYear()- Intervals per year
PerMinute(decimal quantity)- Total output per minute for given quantityPerHour(decimal quantity)- Total output per hour for given quantityPerDay(decimal quantity)- Total output per day for given quantityPerWeek(decimal quantity)- Total output per week for given quantityPerMonth(decimal quantity)- Total output per month for given quantityPerYear(decimal quantity)- Total output per year for given quantity
MoneyInterval Methods
MoneyInterval overrides the base methods to return monetary amounts:PerMinute()- Dollars per minutePerHour()- Dollars per hourPerDay()- Dollars per dayPerWeek()- Dollars per weekPerMonth()- Dollars per monthPerYear()- Dollars per year
PerMinute(decimal quantity)- Total earnings per minute for given quantityPerHour(decimal quantity)- Total earnings per hour for given quantityPerDay(decimal quantity)- Total earnings per day for given quantityPerWeek(decimal quantity)- Total earnings per week for given quantityPerMonth(decimal quantity)- Total earnings per month for given quantityPerYear(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 periodPerMinute(decimal quantity),PerHour(decimal quantity), etc. - Total output for given quantity
RatioPerMinute()- Total ratio per minute (intervals × ratio)RatioPerHour()- Total ratio per hourRatioPerDay()- Total ratio per dayRatioPerWeek()- Total ratio per weekRatioPerMonth()- Total ratio per monthRatioPerYear()- Total ratio per year
RatioPerMinute(decimal quantity)- Total ratio applied to quantity per minuteRatioPerHour(decimal quantity)- Total ratio applied to quantity per hourRatioPerDay(decimal quantity)- Total ratio applied to quantity per dayRatioPerWeek(decimal quantity)- Total ratio applied to quantity per weekRatioPerMonth(decimal quantity)- Total ratio applied to quantity per monthRatioPerYear(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 periodPerMinute(decimal quantity),PerHour(decimal quantity), etc. - Total output for given quantity
RatePerMinute()- Total rate per minute (intervals × rate)RatePerHour()- Total rate per hourRatePerDay()- Total rate per dayRatePerWeek()- Total rate per weekRatePerMonth()- Total rate per monthRatePerYear()- Total rate per year
RatePerMinute(decimal principal)- Total rate applied to principal per minuteRatePerHour(decimal principal)- Total rate applied to principal per hourRatePerDay(decimal principal)- Total rate applied to principal per dayRatePerWeek(decimal principal)- Total rate applied to principal per weekRatePerMonth(decimal principal)- Total rate applied to principal per monthRatePerYear(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 returndecimal values for maximum precision in financial and rate calculations. Be aware that some conversions may result in repeating decimals.