Omid - Challenge 325

data-challenges
advanced-exercises
🔰 GenCalculate the end date equal to the sum of Start date time and Duration
Published

March 24, 2026

Illustration for Omid - Challenge 325

Challenge Description

🔰 GenCalculate the end date equal to the sum of Start date time and Duration

Solutions

library(tidyverse)
library(readxl)

path = "300-399/325/CH-325 Date Calculation.xlsx"
input = read_excel(path, range = "B2:C8", col_types = c("text", "numeric"))
test  = read_excel(path, range = "D2:D8") %>%
  mutate(`End Time` = dmy_hms(`End Time`))

result = input %>%
  mutate(`Start Date` = dmy_hms(`Start Date`),
         `End Time` = `Start Date` + ddays(`Duration [h:m:s]`))

result$`End Time` == test$`End Time`
# first date incorrect
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Builds the intermediate columns that drive the final result

  • Strengths:

    • The R solution stays close to the workbook rule and keeps the transformation compact.
  • Areas for Improvement:

    • The code assumes the sheet structure and source ranges remain stable.
  • Gem:

    • The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd

path = "300-399/325/CH-325 Date Calculation.xlsx"
input = pd.read_excel(path, usecols="B:C", skiprows=1, nrows=7)
test = pd.read_excel(path, usecols="D:D", skiprows=1, nrows=7)\
    .assign(**{"End Time": lambda df: pd.to_datetime(df["End Time"], dayfirst=True)})

input['Start Date'] = pd.to_datetime(input['Start Date'], dayfirst=True)
input['Duration [h:m:s]'] = pd.to_timedelta(input['Duration [h:m:s]'])
input['End Time Calc'] = input['Start Date'] + input['Duration [h:m:s]']

print(input['End Time Calc'] == test['End Time']) # One result incorect
  • Logic:

    • Reads the workbook ranges needed for the challenge

    • Builds the intermediate columns that drive the final result

  • Strengths:

    • The Python version follows the same rule in a direct dataframe-oriented implementation.
  • Areas for Improvement:

    • The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
  • Gem:

    • The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.

Difficulty Level

This task is moderate:

  • The business rule is readable, but the workbook still requires careful implementation to reach the expected layout.