pto refactor

This commit is contained in:
2024-03-08 15:30:08 -07:00
parent 17cfc440b6
commit 8037130431

View File

@@ -1,53 +1,62 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from datetime import datetime, timedelta from datetime import datetime, timedelta
def calculate_reach_date(current_hours, max_hours, hours_added_bi_weekly): def calculate_reach_date(current_hours, max_hours, hours_added_bi_weekly):
""" """
Calculate the date when the maximum allowed hours will be reached. Calculates the estimated date when the maximum Paid Time Off (PTO) hours will be reached.
Parameters: Parameters:
- current_hours (float): The current total hours provided by the user. - current_hours (float): The current total of PTO hours accumulated by the user.
- max_hours (float): The maximum hours allowed. - max_hours (float): The maximum PTO hours that can be accumulated.
- hours_added_bi_weekly (float): The number of hours added every two weeks. - hours_added_bi_weekly (float): The number of PTO hours added every two weeks.
Returns: Returns:
- datetime.date: The estimated date when the max hours will be reached. - datetime.date: The estimated date when the maximum PTO balance is reached.
""" """
# Calculate the difference needed to reach max # Calculate the additional hours needed to reach the maximum
hours_needed = max_hours - current_hours hours_needed = max_hours - current_hours
# Calculate the number of bi-weekly periods needed # Determine the number of bi-weekly periods needed to accumulate the necessary hours
bi_weekly_periods_needed = hours_needed / hours_added_bi_weekly bi_weekly_periods_needed = hours_needed / hours_added_bi_weekly
# Calculate the days needed # Convert the period into days
days_needed = bi_weekly_periods_needed * 14 # 14 days in 2 weeks days_needed = bi_weekly_periods_needed * 14 # Two weeks per bi-weekly period
# Calculate the reach date
current_date = datetime.now()
reach_date = current_date + timedelta(days=days_needed)
# Calculate the future date when the maximum will be reached
reach_date = datetime.now() + timedelta(days=days_needed)
return reach_date return reach_date
# Constants # Constants for the program
MAX_HOURS = 240 MAX_HOURS = 240 # The maximum PTO balance allowed
# The standard rate of PTO accrual every two weeks
HOURS_ADDED_BI_WEEKLY = 6.15384615 HOURS_ADDED_BI_WEEKLY = 6.15384615
# An alternative accrual rate for different scenarios (commented out by default)
# HOURS_ADDED_BI_WEEKLY = 7.69230769 # HOURS_ADDED_BI_WEEKLY = 7.69230769
LAST_KNOWN_PTO_BALANCE = 220.08 # Example last known PTO balance LAST_KNOWN_PTO_BALANCE = 220.08 # An example of a last known PTO balance
# Display the last known PTO balance for easy copying # Introduction and instructions for the user
print(f"Last known PTO balance: {LAST_KNOWN_PTO_BALANCE}") print("PTO Balance Calculator")
print("----------------------")
print("Determine when you will reach your maximum PTO balance based on your current accrual.")
# User input with a prompt that includes the copy-paste line # Display the last known PTO balance to assist with user input
current_hours_input = input("Enter the current hours (copy and paste the 'Last known PTO balance' here): ") print(f"\nLast known PTO balance: {LAST_KNOWN_PTO_BALANCE}\n")
# Convert input to float # Handling user input
current_hours = float(current_hours_input.strip()) try:
# Prompting the user to enter their current PTO balance
current_hours_input = input("Enter your current PTO hours: ")
current_hours = float(current_hours_input.strip()) # Convert input to a floating-point number
# Calculate # Calculation based on user input
reach_date = calculate_reach_date(current_hours, MAX_HOURS, HOURS_ADDED_BI_WEEKLY) reach_date = calculate_reach_date(current_hours, MAX_HOURS, HOURS_ADDED_BI_WEEKLY)
# Output # Displaying the calculation results
print(f"Current date: {datetime.now().strftime('%Y-%m-%d')}") print("\nCalculation Results")
print(f"You will reach the maximum hours on: {reach_date.strftime('%Y-%m-%d')}") print("-------------------")
print(f"Today's Date: {datetime.now().strftime('%A, %B %d, %Y')}")
print(f"Maximum PTO balance of {MAX_HOURS} hours will be reached on: {reach_date.strftime('%A, %B %d, %Y')}.")
except ValueError:
# Error handling for non-numeric inputs
print("Error: Please enter a valid number for your current PTO hours.")