mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
calendar: simpler khal parsing
- assuming 12 is always MM 21 is always dd, 2013 is always yyyy
This commit is contained in:
@@ -15,7 +15,6 @@ Singleton {
|
|||||||
property date lastStartDate
|
property date lastStartDate
|
||||||
property date lastEndDate
|
property date lastEndDate
|
||||||
property string khalDateFormat: "MM/dd/yyyy"
|
property string khalDateFormat: "MM/dd/yyyy"
|
||||||
property var khalDateParser: null
|
|
||||||
|
|
||||||
function checkKhalAvailability() {
|
function checkKhalAvailability() {
|
||||||
if (!khalCheckProcess.running)
|
if (!khalCheckProcess.running)
|
||||||
@@ -28,54 +27,10 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseKhalDateFormat(formatExample) {
|
function parseKhalDateFormat(formatExample) {
|
||||||
if (formatExample.includes('-') && formatExample.indexOf('-') < 4) {
|
let qtFormat = formatExample.replace("12", "MM").replace("21", "dd").replace("2013", "yyyy")
|
||||||
return {
|
return { format: qtFormat, parser: null }
|
||||||
format: "yyyy-MM-dd",
|
|
||||||
parser: parseyyyyMMdd
|
|
||||||
}
|
|
||||||
} else if (formatExample.includes('/')) {
|
|
||||||
let parts = formatExample.split('/')
|
|
||||||
if (parts.length === 3) {
|
|
||||||
let firstPart = parseInt(parts[0])
|
|
||||||
let secondPart = parseInt(parts[1])
|
|
||||||
if (firstPart > 12) {
|
|
||||||
return {
|
|
||||||
format: "dd/MM/yyyy",
|
|
||||||
parser: parseddMMyyyy
|
|
||||||
}
|
|
||||||
} else if (secondPart > 12) {
|
|
||||||
return {
|
|
||||||
format: "MM/dd/yyyy",
|
|
||||||
parser: parseMMddyyyy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
format: "MM/dd/yyyy",
|
|
||||||
parser: parseMMddyyyy
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
format: "MM/dd/yyyy",
|
|
||||||
parser: parseMMddyyyy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseMMddyyyy(dateStr) {
|
|
||||||
let parts = dateStr.split('/')
|
|
||||||
return new Date(parseInt(parts[2]), parseInt(parts[0]) - 1, parseInt(parts[1]))
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseddMMyyyy(dateStr) {
|
|
||||||
let parts = dateStr.split('/')
|
|
||||||
return new Date(parseInt(parts[2]), parseInt(parts[1]) - 1, parseInt(parts[0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseyyyyMMdd(dateStr) {
|
|
||||||
let parts = dateStr.split('-')
|
|
||||||
return new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]))
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadCurrentMonth() {
|
function loadCurrentMonth() {
|
||||||
if (!root.khalAvailable)
|
if (!root.khalAvailable)
|
||||||
@@ -147,7 +102,6 @@ Singleton {
|
|||||||
let formatExample = line.substring(line.indexOf(':') + 1).trim()
|
let formatExample = line.substring(line.indexOf(':') + 1).trim()
|
||||||
let formatInfo = parseKhalDateFormat(formatExample)
|
let formatInfo = parseKhalDateFormat(formatExample)
|
||||||
root.khalDateFormat = formatInfo.format
|
root.khalDateFormat = formatInfo.format
|
||||||
root.khalDateParser = formatInfo.parser
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,15 +154,15 @@ Singleton {
|
|||||||
if (!event.title)
|
if (!event.title)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
// Parse start and end dates using detected parser
|
// Parse start and end dates using detected format
|
||||||
let startDate, endDate
|
let startDate, endDate
|
||||||
if (event['start-date']) {
|
if (event['start-date']) {
|
||||||
startDate = root.khalDateParser ? root.khalDateParser(event['start-date']) : parseMMddyyyy(event['start-date'])
|
startDate = Date.fromLocaleString(Qt.locale(), event['start-date'], root.khalDateFormat)
|
||||||
} else {
|
} else {
|
||||||
startDate = new Date()
|
startDate = new Date()
|
||||||
}
|
}
|
||||||
if (event['end-date']) {
|
if (event['end-date']) {
|
||||||
endDate = root.khalDateParser ? root.khalDateParser(event['end-date']) : parseMMddyyyy(event['end-date'])
|
endDate = Date.fromLocaleString(Qt.locale(), event['end-date'], root.khalDateFormat)
|
||||||
} else {
|
} else {
|
||||||
endDate = new Date(startDate)
|
endDate = new Date(startDate)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user