It is currently May 19th, 2021, 12:40 am

week number problem

Help with creating, editing & fixing problems with skins
User avatar
Ivan
Posts: 258
Joined: January 27th, 2012, 6:37 pm
Location: Belgrade, Serbia

week number problem

Post by Ivan »

Hi,

I have a problem with skin that show week number and day in year number. Problem is that first week of 2013 is numbered as 00 and i need it as 01, can somebody help me with this?

this is skin i am using

Code: Select all

[Variables]
Font=Calibri
FontSize1=16
FontSize2=12
FontSize3=8
Color1=255,255,255,255

;---------------------------------------------------------------------
; MEASURES

[MeasureWeek]
Measure=Time
Format="%W"

[MeasureDate]
Measure=Time
Format="%j"

;---------------------------------------------------------------------
; METERS

[LabelWEEK]
Meter=String
Text="WEEK No."

FontFace=#Font#
FontSize=#FontSize3#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1

X=0
Y=0

[Week]
Meter=STRING
FontFace=#Font#
FontSize=#FontSize1#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1
X=0
Y=8
MeasureName=MeasureWeek

[LabelDAY]
Meter=String
Text="DAY No."

FontFace=#Font#
FontSize=#FontSize3#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1

X=0
Y=35

[Date]
Meter=STRING
FontFace=#Font#
FontSize=#FontSize2#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1
X=0
Y=45
MeasureName=MeasureDate
StarburstSpectrum
Posts: 35
Joined: November 28th, 2012, 1:10 pm
Location: Canada

Re: week number problem

Post by StarburstSpectrum »

You could add a Calc Measure.

Code: Select all

[MeasureWeek]
Measure=Time
Format="%W"

[WeekCalc]
Measure=Calc
Formula=(MeasureWeek + 1)
.
.
.
[Week]
Meter=STRING
FontFace=#Font#
FontSize=#FontSize1#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1
X=0
Y=8
MeasureName=WeekCalc
And if you want the leading 0 back you could add another measure:

Code: Select all

[MeasureWeek]
Measure=Time
Format="%W"

[Week0]
Measure=Calc
Formula=(MeasureWeek < 9) ? 0 : 1
Substitute="1":""

[WeekCalc]
Measure=Calc
Formula=(MeasureWeek + 1)
.
.
.
[Week]
Meter=STRING
FontFace=#Font#
FontSize=#FontSize1#
FontColor=#Color1#
StringStyle=Normal
StringAlign=left
AntiAlias=1
X=0
Y=8
MeasureName=WeekCalc
MeasureName2=Week0
Text="%2%1"
User avatar
Ivan
Posts: 258
Joined: January 27th, 2012, 6:37 pm
Location: Belgrade, Serbia

Re: week number problem

Post by Ivan »

Thank you!
jpyllman
Posts: 5
Joined: January 18th, 2013, 8:27 am

Re: week number problem

Post by jpyllman »

I do not really think this is a good solution. Cause the main reason for this problem is that the %W, and %U for that matter does not count weeks as ISO does. Normal date function in UNIX/Linux have an extra %V that handles the ISO way of telling what week number it is. The %W/%U differ from %V when 1st of January is a Monday to Thursday. When 1st of January is Friday to Sunday they will show the same.

So the best solution is if Rainmeter would supply a %V that return the ISO week number for all of us that follow the ISO way of deciding the number on the week.

The workaround is using formula and the date 1st of January of the same year to calculate the 'correct' week number.
jpyllman
Posts: 5
Joined: January 18th, 2013, 8:27 am

Re: week number problem

Post by jpyllman »

One workaround could be this.

Code: Select all

[measureNowDY]
; Current day of the year
Measure=Time
Format=%#j

[measureNowWD]
; Current day of the week
Measure=Time
Format=%#w

[measureX]
; Calculate what day of the week is first of January
Measure=Calc
Formula=((measureNowWD+7)-(measureNowDY-1)%7)%7

[measureNowW]
; Current week number
Measure=Time
Format=%#W

[measureWeek]
; Returns the ISO week number
Measure=Calc
Formula=((measureX = 0) || (measureX >= 5)) ? measureNowW : measureNowW+1
I have not tested it for all possible combinations. But measureX gives the number I was looking for for the coming years. Please comment on this.
jpyllman
Posts: 5
Joined: January 18th, 2013, 8:27 am

Re: week number problem

Post by jpyllman »

Actually, what this workaround does not handle is when you get 0 from %W and it does not add +1. That is actually correct. But then it should say 52 or 53 depending on what number the last week of the previous year have. Not perfect for the first week 0 when it is a year when you do not add +1.
StarburstSpectrum
Posts: 35
Joined: November 28th, 2012, 1:10 pm
Location: Canada

Re: week number problem

Post by StarburstSpectrum »

" Please comment on this."
Is that for me or for the rainmeter team?

This seems like a question for the rainmeter team, as all I did was add 1 to the value rainmeter gave me. Your formula's may be more accurate but not necessary for most people I would think.
jpyllman
Posts: 5
Joined: January 18th, 2013, 8:27 am

Re: week number problem

Post by jpyllman »

"please comment" was just to get some feedback from anybody who had anything to say.

Adding 1 to the week number from %W in a Measure=Time will work 2013,2014,2015. But do not work 2012,2016,2017. So it is all about if you want to change between +1 or +0 depending on what year it is. %W=0 in 2012,2016,2017 actually mean the week number of the last week the year before. %W=0 in 2013,2014,2015 mean week number 1. At least if you are talking about ISO week numbers.
StarburstSpectrum
Posts: 35
Joined: November 28th, 2012, 1:10 pm
Location: Canada

Re: week number problem

Post by StarburstSpectrum »

I see what your talking about now. 2016 seemed fine for me, but 2017 definitely had the problem, If your week started on Monday it would be ok, but my week starts on Sunday making that the 2nd week. It does bug me now that I see it.
jpyllman
Posts: 5
Joined: January 18th, 2013, 8:27 am

Re: week number problem

Post by jpyllman »

It sure does. Actually, if the week starts with Sunday you should use %U. %W is for weeks starting on Monday. But the way most calendars count weeks is the ISO way where it depends on which day is 1st of January is. Time and date is so much fun. If you want to look at calendars from all over the world and see all the differences go to http://timeanddate.com/.