It is currently March 28th, 2024, 1:01 pm

You say it's your birthday, well it's my birthday too yeah

Clocks and timer skins
Post Reply
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

You say it's your birthday, well it's my birthday too yeah

Post by jsmorley »

Birthday_1.1.rmskin
(1.94 MiB) Downloaded 151 times
1.png
Birthday.ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,1

[Variables]
MyBirthday=April 25, 1974

[MeasureScript]
Measure=Script
ScriptFile=Birthday.lua
UpdateDivider=-1

[MeterAge]
Meter=String
FontFace=Fira Sans
FontSize=12
FontWeight=400
FontColor=215,239,252,255
AntiAlias=1
DynamicVariables=1
InlineSetting=Color | 137,209,250
InlinePattern=#MyAge#
Text=You are #MyAge# years old.

[MeterBirthday]
Meter=String
FontFace=Fira Sans
X=([MeterAge:X]+[MeterAge:W]+10)
Y=0r
FontSize=12
FontWeight=400
FontColor=215,239,252,255
AntiAlias=1
DynamicVariables=1
InlineSetting=Color | 137,209,250
InlinePattern=Birthday!
Text=Today is your Birthday!
Hidden=1

[MeterNext]
Meter=String
Group=Next
X=([MeterAge:X]+[MeterAge:W]+10)
Y=0r
FontFace=Fira Sans
FontSize=12
FontWeight=400
FontColor=215,239,252,255
AntiAlias=1
DynamicVariables=1
InlineSetting=Color | 137,209,250
InlinePattern=#NextBirtday#
Text=Your next birthday is on #NextBirtday#,

[MeterDays]
Meter=String
Group=Next
X=5R
Y=0r
FontFace=Fira Sans
FontSize=12
FontWeight=400
FontColor=215,239,252,255
AntiAlias=1
DynamicVariables=1
InlineSetting=Color | 137,209,250
InlinePattern=#DaysTil#
Text=in #DaysTil# days.
Birthday.lua:

Code: Select all

function Initialize()

		dofile(SKIN:GetVariable('@')..'date\\date.lua')
		
end

function Update()

	myBirthday = SKIN:GetVariable('MyBirthday')
	
	myDate = date(myBirthday)
	myYear, myMonth, myDay = myDate:getdate()

	currentDate = date()
	currentYear, currentMonth, currentDay = currentDate:getdate()

	myAge = math.floor(date.diff(currentDate, myDate):spandays() / 365)
	
	if date(currentYear, myMonth, myDay) >= currentDate then
		nextBirthday = date(currentYear, myMonth, myDay):fmt('%A, %B %d, %Y')
	else
		nextBirthday = date(currentYear+1, myMonth, myDay):fmt('%A, %B %d, %Y')
	end
	
	daysTilBirthday = math.abs(math.ceil(date.diff(nextBirthday, currentDate):spandays()))
	
	SKIN:Bang('!SetVariable', 'MyAge', myAge)
	SKIN:Bang('!SetVariable', 'NextBirtday', nextBirthday)
	SKIN:Bang('!SetVariable', 'DaysTil', daysTilBirthday)
	
	if daysTilBirthday > 0 then
		SKIN:Bang('!SetOptionGroup', 'Next', 'Hidden', '0')
		SKIN:Bang('!SetOption', 'MeterBirthday', 'Hidden', '1')
	else
		SKIN:Bang('!SetOptionGroup', 'Next', 'Hidden', '1')
		SKIN:Bang('!SetOption', 'MeterBirthday', 'Hidden', '0')
	end
	
end
This demonstrates a couple of thing.

1) Using dofile() in Lua to load an external library of Lua code to call and use in your script.
2) The date.lua library, which has some exceptional date / time handling that you can use.

The date.lua library is included with the skin, and can be found in @Resources\date\ in the skin after you install it.
The documentation for date.lua is at:
http://tieske.github.io/date/

Note: This uses a date.lua designed for Lua version 5.1. There is a version out there that is changed to target Lua version 5.2, but we have not implemented the 5.2 or the new 5.3.4 version of Lua in Rainmeter, due to possible backwards compatibility issues. So use the date.lua I have included, and not one you download from the web.
andre85
Posts: 1
Joined: August 19th, 2017, 8:14 am

Re: You say it's your birthday, well it's my birthday too yeah

Post by andre85 »

You've got one error in your Birtday.lua.
Line 19:

Code: Select all

	if currentMonth <= myMonth then
This needs to be by day:

Code: Select all

	if currentDay <= myDay then
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: You say it's your birthday, well it's my birthday too yeah

Post by jsmorley »

andre85 wrote:You've got one error in your Birtday.lua.
Line 19:

Code: Select all

	if currentMonth <= myMonth then
This needs to be by day:

Code: Select all

	if currentDay <= myDay then
No, the currrentMonth <= myMonth bit is to deal the next birthday being in this calendar year, or in the next. It's early, and I haven't had my coffee yet, but I'm pretty sure it's right.

Edit: Hmm.. You might be right, if the birthday is in the current month, that might fall apart. Let me get that coffee and chew on this.

Edit: Yeah, good catch. It needs to consider both the month and day if the birthday is in the current month, past or future. Fixed the code and .rmskin in the first post. Thanks.
Post Reply