Skip to content

Commit

Permalink
Fix issue due to PlasmaCalendar returning wrong year
Browse files Browse the repository at this point in the history
PlasmaCalendar year property is returning 0, what breaks the logic of
getting which was the day of the week of Jan 1st, current year.
This commit relies on JS Date object functions to get the current year.
Also, it fixes a old and dumb issue in this plasmoid due to the fact
January in JavaScript is 0, not 1.
  • Loading branch information
anselmolsm committed Jan 10, 2019
1 parent 2597912 commit 6980101
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contents/ui/CompactRepresentation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.0
import QtQuick 2.12
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.calendar 2.0 as PlasmaCalendar
Expand All @@ -38,10 +38,11 @@ PlasmaComponents.Label {

if (plasmoid.configuration.firstWeekOfYearIndex == 1) {
// Check if January 1st is after Wednesday.
var date = new Date(calendarBackend.year, 1, 1);
var firstJanDayofWeek = date.getDay();
var date = new Date();
var janFirst = new Date(date.getFullYear(), 0, 1); // January is 0 in JS
var janFirstDayOfWeek = janFirst.getDay();
// Wednesday == 3, week starting on Sunday
if (firstJanDayofWeek > 3)
if (janFirstDayOfWeek > 3)
week = week + 1;
}
return week < 10 ? "0" + week : week
Expand Down

0 comments on commit 6980101

Please sign in to comment.