Skip to content

Commit

Permalink
鈾伙笍 rewrite calendar.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lostdesign committed Mar 29, 2021
1 parent 9e00db6 commit a9e3e0c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
6 changes: 5 additions & 1 deletion package.json
@@ -1,7 +1,10 @@
{
"name": "linked",
"version": "1.0.5",
"keywords": ["journal", "calendar"],
"keywords": [
"journal",
"calendar"
],
"description": "Link your thoughts to days.",
"author": "Andr茅 Weller <info@lost.design> (https://lost.design/)",
"license": "MIT",
Expand Down Expand Up @@ -50,6 +53,7 @@
"electron-store": "^6.0.0",
"electron-updater": "^4.3.4",
"highlight.js": "^10.6.0",
"luxon": "^1.26.0",
"vue": "^2.6.11",
"vue-router": "^3.2.0"
},
Expand Down
59 changes: 23 additions & 36 deletions src/mixins/calendar.js
@@ -1,39 +1,50 @@
import { DateTime } from "luxon"

export default {
data () {
return {
today: this.formatDate(new Date(), 'year-mm-dd')
today: this.getToday()
}
},
methods: {
getToday() {
return DateTime.now().toISODate()
},
/**
* Set the current day by click.
* @param {*} day
* @returns
*/
setDay(day) {
this.today = this.formatDate(day, 'year-mm-dd')
this.today = DateTime.fromISO(day).toISODate()
},
/**
* Takes in any integer and shifts the date by the value of the integer. Returns a normal date string.
* @param {number} day
* @param {string} date
* @returns {string} date
*/
shiftDay(date, day) {
return new Date(date).setDate(new Date(date).getDate() + day)
shiftDay(day) {
this.today = DateTime.fromISO(this.today).plus({days: day}).toISODate()
},
/**
* Returns an array of date strings in YYYY-mm-dd for the current active week
*/
currentWeek() {
const curr = new Date(this.today)
getCurrentWeekDates() {
let week = []
const startOfWeek = DateTime.fromISO(this.today).startOf('week')

for (let i = 1; i <= 7; i++) {
let first = curr.getDate() - curr.getDay() + i
week.push(new Date(curr.setDate(first)).toISOString().slice(0, 10))
// TODO get locale from state
for (let i = 0; i <= 6; i++) {
let day = startOfWeek.plus({days: i}).setLocale('de-DE')
week.push(
{
isoDate: day.toISODate(),
day: day.toFormat('d'),
weekDay: day.toFormat('ccccc'),
}
)
}

return week
},
/**
Expand All @@ -42,32 +53,8 @@ export default {
* @param {string} format
* @returns {string}
*/
formatDate(date, format) {
const dt = new Date(date)
const map = {
mm: dt.getMonth() + 1,
dd: dt.getDate(),
yy: dt.getFullYear().toString().slice(-2),
year: dt.getFullYear(),
day: this.weekDay(dt.getDay())
}

return format.replace(/mm|dd|yy|year|day/gi, matched => map[matched])
},
weekDay(day) {
const map = {
0: 'S', 1: 'M', 2: 'D', 3: 'M', 4: 'D', 5: 'F', 6: 'S'
}
return map[day]
},
/**
* Takes an array and two indexes to return a new spliced array by given indexes.
* @param {array} array
* @param {integer} from
* @param {integer} to
*/
returnDatesArrayFromTo(array, from, to) {
return array.slice(from,to)
formatDate(format) {
return DateTime.fromISO(this.today).toFormat(format)
},
},
watch: {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/file.js
Expand Up @@ -10,15 +10,15 @@ export default {
methods: {
saveFile() {
ipcRenderer.invoke('save-file', [
this.formatDate(this.today, 'year'),
this.formatDate('y'),
this.today,
this.content,
this.rating
])
},
loadFile() {
ipcRenderer.invoke('load-file', [
this.formatDate(this.today, 'year'),
this.formatDate('y'),
this.today
]).then(data => {
this.content = data.content
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -7202,6 +7202,11 @@ lru_map@^0.3.3:
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=

luxon@^1.26.0:
version "1.26.0"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.26.0.tgz#d3692361fda51473948252061d0f8561df02b578"
integrity sha512-+V5QIQ5f6CDXQpWNICELwjwuHdqeJM1UenlZWx5ujcRMc9venvluCjFb4t5NYLhb6IhkbMVOxzVuOqkgMxee2A==

make-dir@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"
Expand Down

0 comments on commit a9e3e0c

Please sign in to comment.