Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Proxiwash.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // @flow
  2. import type {Machine} from "../screens/Proxiwash/ProxiwashScreen";
  3. /**
  4. * Gets the machine end Date object.
  5. * If the time is before the current time, it will be considered as tomorrow
  6. *
  7. * @param machine The machine to get the date from
  8. * @returns {Date} The date object representing the end time.
  9. */
  10. export function getMachineEndDate(machine: Machine) {
  11. const array = machine.endTime.split(":");
  12. let date = new Date(Date.now());
  13. date.setHours(parseInt(array[0]), parseInt(array[1]));
  14. if (date < new Date(Date.now()))
  15. date.setDate(date.getDate() + 1);
  16. return date;
  17. }
  18. /**
  19. * Checks whether the machine of the given ID has scheduled notifications
  20. *
  21. * @param machine The machine to check
  22. * @param machineList The machine list
  23. * @returns {boolean}
  24. */
  25. export function isMachineWatched(machine: Machine, machineList: Array<Machine>) {
  26. let watched = false;
  27. for (let i = 0; i < machineList.length; i++) {
  28. if (machineList[i].number === machine.number && machineList[i].endTime === machine.endTime) {
  29. watched = true;
  30. break;
  31. }
  32. }
  33. return watched;
  34. }
  35. /**
  36. * Gets the machine of the given id
  37. *
  38. * @param id The machine's ID
  39. * @param allMachines The machine list
  40. * @returns {null|Machine} The machine or null if not found
  41. */
  42. export function getMachineOfId(id: string, allMachines: Array<Machine>) {
  43. for (let i = 0; i < allMachines.length; i++) {
  44. if (allMachines[i].number === id)
  45. return allMachines[i];
  46. }
  47. return null;
  48. }
  49. /**
  50. * Gets a cleaned machine watched list by removing invalid entries.
  51. * An entry is considered invalid if the end time in the watched list
  52. * and in the full list does not match (a new machine cycle started)
  53. *
  54. * @param machineWatchedList The current machine watch list
  55. * @param allMachines The current full machine list
  56. * @returns {Array<Machine>}
  57. */
  58. export function getCleanedMachineWatched(machineWatchedList: Array<Machine>, allMachines: Array<Machine>) {
  59. let newList = [];
  60. for (let i = 0; i < machineWatchedList.length; i++) {
  61. let machine = getMachineOfId(machineWatchedList[i].number, allMachines);
  62. if (machine !== null
  63. && machineWatchedList[i].number === machine.number
  64. && machineWatchedList[i].endTime === machine.endTime) {
  65. newList.push(machine);
  66. }
  67. }
  68. return newList;
  69. }