Ohm-Management - Projektarbeit B-ME
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.

VDatePickerDateTable.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _datePickerTable = require('./mixins/date-picker-table');
  6. var _datePickerTable2 = _interopRequireDefault(_datePickerTable);
  7. var _util = require('./util');
  8. var _helpers = require('../../util/helpers');
  9. var _mixins = require('../../util/mixins');
  10. var _mixins2 = _interopRequireDefault(_mixins);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. // Mixins
  13. exports.default = (0, _mixins2.default)(_datePickerTable2.default
  14. /* @vue/component */
  15. ).extend({
  16. name: 'v-date-picker-date-table',
  17. props: {
  18. firstDayOfWeek: {
  19. type: [String, Number],
  20. default: 0
  21. },
  22. showWeek: Boolean,
  23. weekdayFormat: Function
  24. },
  25. computed: {
  26. formatter: function formatter() {
  27. return this.format || (0, _util.createNativeLocaleFormatter)(this.locale, { day: 'numeric', timeZone: 'UTC' }, { start: 8, length: 2 });
  28. },
  29. weekdayFormatter: function weekdayFormatter() {
  30. return this.weekdayFormat || (0, _util.createNativeLocaleFormatter)(this.locale, { weekday: 'narrow', timeZone: 'UTC' });
  31. },
  32. weekDays: function weekDays() {
  33. var _this = this;
  34. var first = parseInt(this.firstDayOfWeek, 10);
  35. return this.weekdayFormatter ? (0, _helpers.createRange)(7).map(function (i) {
  36. return _this.weekdayFormatter('2017-01-' + (first + i + 15));
  37. }) // 2017-01-15 is Sunday
  38. : (0, _helpers.createRange)(7).map(function (i) {
  39. return ['S', 'M', 'T', 'W', 'T', 'F', 'S'][(i + first) % 7];
  40. });
  41. }
  42. },
  43. methods: {
  44. calculateTableDate: function calculateTableDate(delta) {
  45. return (0, _util.monthChange)(this.tableDate, Math.sign(delta || 1));
  46. },
  47. genTHead: function genTHead() {
  48. var _this2 = this;
  49. var days = this.weekDays.map(function (day) {
  50. return _this2.$createElement('th', day);
  51. });
  52. this.showWeek && days.unshift(this.$createElement('th'));
  53. return this.$createElement('thead', this.genTR(days));
  54. },
  55. // Returns number of the days from the firstDayOfWeek to the first day of the current month
  56. weekDaysBeforeFirstDayOfTheMonth: function weekDaysBeforeFirstDayOfTheMonth() {
  57. var firstDayOfTheMonth = new Date(this.displayedYear + '-' + (0, _util.pad)(this.displayedMonth + 1) + '-01T00:00:00+00:00');
  58. var weekDay = firstDayOfTheMonth.getUTCDay();
  59. return (weekDay - parseInt(this.firstDayOfWeek) + 7) % 7;
  60. },
  61. getWeekNumber: function getWeekNumber() {
  62. var dayOfYear = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334][this.displayedMonth];
  63. if (this.displayedMonth > 1 && (this.displayedYear % 4 === 0 && this.displayedYear % 100 !== 0 || this.displayedYear % 400 === 0)) {
  64. dayOfYear++;
  65. }
  66. var offset = (this.displayedYear + (this.displayedYear - 1 >> 2) - Math.floor((this.displayedYear - 1) / 100) + Math.floor((this.displayedYear - 1) / 400) - Number(this.firstDayOfWeek)) % 7; // https://en.wikipedia.org/wiki/Zeller%27s_congruence
  67. return Math.floor((dayOfYear + offset) / 7) + 1;
  68. },
  69. genWeekNumber: function genWeekNumber(weekNumber) {
  70. return this.$createElement('td', [this.$createElement('small', {
  71. staticClass: 'v-date-picker-table--date__week'
  72. }, String(weekNumber).padStart(2, '0'))]);
  73. },
  74. genTBody: function genTBody() {
  75. var children = [];
  76. var daysInMonth = new Date(this.displayedYear, this.displayedMonth + 1, 0).getDate();
  77. var rows = [];
  78. var day = this.weekDaysBeforeFirstDayOfTheMonth();
  79. var weekNumber = this.getWeekNumber();
  80. this.showWeek && rows.push(this.genWeekNumber(weekNumber++));
  81. while (day--) {
  82. rows.push(this.$createElement('td'));
  83. }for (day = 1; day <= daysInMonth; day++) {
  84. var date = this.displayedYear + '-' + (0, _util.pad)(this.displayedMonth + 1) + '-' + (0, _util.pad)(day);
  85. rows.push(this.$createElement('td', [this.genButton(date, true, 'date', this.formatter)]));
  86. if (rows.length % (this.showWeek ? 8 : 7) === 0) {
  87. children.push(this.genTR(rows));
  88. rows = [];
  89. day < daysInMonth && this.showWeek && rows.push(this.genWeekNumber(weekNumber++));
  90. }
  91. }
  92. if (rows.length) {
  93. children.push(this.genTR(rows));
  94. }
  95. return this.$createElement('tbody', children);
  96. },
  97. genTR: function genTR(children) {
  98. return [this.$createElement('tr', children)];
  99. }
  100. },
  101. render: function render() {
  102. return this.genTable('v-date-picker-table v-date-picker-table--date', [this.genTHead(), this.genTBody()], this.calculateTableDate);
  103. }
  104. });
  105. // Utils
  106. //# sourceMappingURL=VDatePickerDateTable.js.map