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.

times.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Vue from 'vue';
  2. import { validateTimestamp, parseTimestamp, parseDate } from '../util/timestamp';
  3. export default Vue.extend({
  4. name: 'times',
  5. props: {
  6. now: {
  7. type: String,
  8. validator: validateTimestamp
  9. }
  10. },
  11. data: function data() {
  12. return {
  13. times: {
  14. now: parseTimestamp('0000-00-00 00:00'),
  15. today: parseTimestamp('0000-00-00')
  16. }
  17. };
  18. },
  19. computed: {
  20. parsedNow: function parsedNow() {
  21. return this.now ? parseTimestamp(this.now) : null;
  22. }
  23. },
  24. watch: {
  25. parsedNow: 'updateTimes'
  26. },
  27. created: function created() {
  28. this.updateTimes();
  29. this.setPresent();
  30. },
  31. methods: {
  32. setPresent: function setPresent() {
  33. this.times.now.present = this.times.today.present = true;
  34. this.times.now.past = this.times.today.past = false;
  35. this.times.now.future = this.times.today.future = false;
  36. },
  37. updateTimes: function updateTimes() {
  38. var now = this.parsedNow || this.getNow();
  39. this.updateDay(now, this.times.now);
  40. this.updateTime(now, this.times.now);
  41. this.updateDay(now, this.times.today);
  42. },
  43. getNow: function getNow() {
  44. return parseDate(new Date());
  45. },
  46. updateDay: function updateDay(now, target) {
  47. if (now.date !== target.date) {
  48. target.year = now.year;
  49. target.month = now.month;
  50. target.day = now.day;
  51. target.weekday = now.weekday;
  52. target.date = now.date;
  53. }
  54. },
  55. updateTime: function updateTime(now, target) {
  56. if (now.time !== target.time) {
  57. target.hour = now.hour;
  58. target.minute = now.minute;
  59. target.time = now.time;
  60. }
  61. }
  62. }
  63. });
  64. //# sourceMappingURL=times.js.map