Loggest thine Stuff
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.

77 lines
2.2 KiB

2 years ago
2 years ago
2 years ago
  1. <script lang="ts">
  2. import { endOfMonth, endOfWeek, endOfYear, formatDate, nextMonth, nextYear } from "$lib/utils/date";
  3. export let value: string;
  4. export let openDate: Date;
  5. export let notScheduledText = "Not Scheduled";
  6. let selected: "none" | "date" | "eod" | "eot" | "eow" | "eonw" | "eonnw" | "eom" | "eonm" | "eoy" | "eony" = !!value ? "date" : "none";
  7. $: {
  8. switch (selected) {
  9. case "eod":
  10. value = formatDate(openDate);
  11. break;
  12. case "eot":
  13. value = formatDate(new Date(openDate.getTime() + 86400000));
  14. break;
  15. case "eow":
  16. value = formatDate(endOfWeek(openDate))
  17. break;
  18. case "eonw":
  19. value = formatDate(endOfWeek(new Date(openDate.getTime() + (86400000 * 7))))
  20. break;
  21. case "eonnw":
  22. value = formatDate(endOfWeek(new Date(openDate.getTime() + (86400000 * 14))))
  23. break;
  24. case "eom":
  25. value = formatDate(endOfMonth(openDate))
  26. break;
  27. case "eonm":
  28. value = formatDate(endOfMonth(nextMonth(openDate)))
  29. break;
  30. case "eoy":
  31. value = formatDate(endOfYear(openDate))
  32. break;
  33. case "eony":
  34. value = formatDate(endOfYear(nextYear(openDate)))
  35. break;
  36. case "date":
  37. if (value == "") {
  38. value = formatDate(openDate);
  39. }
  40. break;
  41. case "none":
  42. value = "";
  43. break;
  44. }
  45. }
  46. </script>
  47. <select bind:value={selected}>
  48. <option value="none">{notScheduledText}</option>
  49. <option value="eod">Today</option>
  50. <option value="eot">Tomorrow</option>
  51. <option value="eow">Sunday</option>
  52. <option value="eonw">Next Sunday</option>
  53. <option value="eonnw">The Sunday after Next</option>
  54. <option value="eom">End of Month</option>
  55. <option value="eonm">End of Next Month</option>
  56. <option value="eoy">End of Year</option>
  57. <option value="eony">End of Next Year</option>
  58. <option value="date">Specific Date</option>
  59. </select>
  60. {#if selected !== "none"}
  61. <input type="date" disabled={selected !== "date"} bind:value={value} />
  62. {/if}
  63. <style>
  64. select {
  65. margin-bottom: 0.25em !important;
  66. }
  67. input {
  68. margin-top: 0 !important;
  69. resize: none !important;
  70. }
  71. </style>