Skip to content

Instantly share code, notes, and snippets.

@ansariabr
Last active December 15, 2019 11:45
Show Gist options
  • Save ansariabr/d47687e42401928c47ec8a583365a68d to your computer and use it in GitHub Desktop.
Save ansariabr/d47687e42401928c47ec8a583365a68d to your computer and use it in GitHub Desktop.
A method to calculate discount based on the time of the day
public decimal CalculateDiscount(decimal totalAmount)
{
decimal discountPercentage;
if (DateTimeOffset.Now.Hour >= 22 || DateTimeOffset.Now.Hour < 6)
discountPercentage = 25;
else
discountPercentage = 10;
return totalAmount - ((totalAmount * discountPercentage) / 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment