using dodohold.core; namespace molilian.core { public class WorkSchedule { private int workHours; public WorkSchedule(int initialWorkHours = 0) => workHours = initialWorkHours; // 检查指定小时是否为工作时间 public bool IsWorkHour(int? hour = null) { int checkHour = hour ?? DateTime.Now.Hour; // 处理小于0或大于24的情况 if (checkHour < 0) { checkHour = Math.Abs(checkHour) % 24; } else if (checkHour >= 24) { checkHour = checkHour % 24; } return (workHours & (1 << checkHour)) != 0; } // 获取工作时间的二进制表示 public int GetWorkHours() { return workHours; } // 设置工作时间的二进制表示 public void SetWorkHours(int hours) { workHours = hours; } // 打印工作时间 public void PrintWorkHours() { Console.WriteLine(Convert.ToString(workHours, 2).PadLeft(24, '0')); } } }