a simple code:
protected void Page_Load(object sender, EventArgs e)
{
DateTime now = DateTime.UtcNow;
lit.Text += "<br/>now.DayOfWeek: " + now.DayOfWeek.ToString();
// weekdays (Saturday is not included)
DayOfWeek runningDays = DayOfWeek.Monday | DayOfWeek.Tuesday | DayOfWeek.Wednesday | DayOfWeek.Thursday | DayOfWeek.Friday;
lit.Text += "<br/>" + runningDays.HasFlag(now.DayOfWeek);
lit.Text += "<br/>" + runningDays.HasAny(now.DayOfWeek);
lit.Text += "<br/>" + ((runningDays & now.DayOfWeek) != 0);
// weekend (Saturday is in a weekend)
runningDays = DayOfWeek.Saturday | DayOfWeek.Sunday;
lit.Text += "<br/>" + runningDays.HasFlag(now.DayOfWeek);
lit.Text += "<br/>" + runningDays.HasAny(now.DayOfWeek);
lit.Text += "<br/>" + ((runningDays & now.DayOfWeek) != 0);
}
A helper:
public static bool HasExactly(this DayOfWeek x, DayOfWeek y) { return x == y; }
public static bool HasAny(this DayOfWeek x, DayOfWeek y) { return 0 != (x & y); }
public static bool HasAll(this DayOfWeek x, DayOfWeek y) { return y == (x & y); }
today's output (Saturday)
now.DayOfWeek: Saturday
True
True
True
True
True
True
But the output should be like:
now.DayOfWeek: Saturday
False
False
False
True
True
True
What am I missing here?