WorkSchedule.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using dodohold.core;
  2. namespace molilian.core
  3. {
  4. public class WorkSchedule
  5. {
  6. private int workHours;
  7. public WorkSchedule(int initialWorkHours = 0) => workHours = initialWorkHours;
  8. // 检查指定小时是否为工作时间
  9. public bool IsWorkHour(int? hour = null)
  10. {
  11. int checkHour = hour ?? DateTime.Now.Hour;
  12. // 处理小于0或大于24的情况
  13. if (checkHour < 0)
  14. {
  15. checkHour = Math.Abs(checkHour) % 24;
  16. }
  17. else if (checkHour >= 24)
  18. {
  19. checkHour = checkHour % 24;
  20. }
  21. return (workHours & (1 << checkHour)) != 0;
  22. }
  23. // 获取工作时间的二进制表示
  24. public int GetWorkHours()
  25. {
  26. return workHours;
  27. }
  28. // 设置工作时间的二进制表示
  29. public void SetWorkHours(int hours)
  30. {
  31. workHours = hours;
  32. }
  33. // 打印工作时间
  34. public void PrintWorkHours()
  35. {
  36. Console.WriteLine(Convert.ToString(workHours, 2).PadLeft(24, '0'));
  37. }
  38. }
  39. }