Thanks to visit codestin.com
Credit goes to github.com

Skip to content

15m Solution #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 15m
Choose a base branch
from
Open

15m Solution #59

wants to merge 1 commit into from

Conversation

SuperSimpleDev
Copy link
Owner

No description provided.

Copy link

@antaugustol antaugustol Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I challenged myself to use a for loop and ended up with this:

export function calculateDeliveryDate(deliveryOption) {
  const newDeliveryDays = skipWeekendDays(deliveryOption.deliveryDays)
  const deliveryDate = today.add(newDeliveryDays, 'd')
  const datestring = deliveryDate.format('dddd, MMMM D')
  return datestring
}

function skipWeekendDays(deliveryDays) {
  for (let i = 1; i <= deliveryDays; i++) {
    const weekDay = today.add(i, 'd').format('dddd')
    if (weekDay === 'Saturday' || weekDay === 'Sunday') {
      deliveryDays++
    }
  }
  return deliveryDays
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this method posed a problem but I hope it doesn't I built my if statements directly into the calculateDeliveryDate() fucntion
image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the same thing, but I think my approach sticks more to the "Separation of Concerns" principle. Thanks for sharing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with this
image

@EliasAllan
Copy link

Tried using an if statement and it worked

`export function calculateDeliveryDate(deliveryOption) {
const today = dayjs();
const { deliveryDays } = deliveryOption;
let deliveryDate = today.add(
deliveryDays,
'days'
);
const deliveryDayofTheWeek = deliveryDate.format(
'dddd'
)
if (deliveryDayofTheWeek === "Saturday") {
deliveryDate = today.add(
deliveryDays + 2,
'days'
);
} else if (deliveryDayofTheWeek === "Sunday") {
deliveryDate = today.add(
deliveryDays + 1,
'days'
);
}

const dateString = deliveryDate.format(
'dddd, MMMM D'
);
return dateString
}`

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.

5 participants