It is currently April 27th, 2024, 4:14 am

Calculation on a string

Get help with creating, editing & fixing problems with skins
TallShultzy
Posts: 62
Joined: March 30th, 2016, 5:02 pm

Calculation on a string

Post by TallShultzy »

A RSS feed I use produces a string "Sat, 13 Jun 13:50". Unfortunately the time is GMT and not summertime. Is there anyway to add 1hr to the time before I display it. I've looked at [Calc] and [Formula] with no luck.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calculation on a string

Post by jsmorley »

TallShultzy wrote: June 13th, 2020, 3:11 pm A RSS feed I use produces a string "Sat, 13 Jun 13:50". Unfortunately the time is GMT and not summertime. Is there anyway to add 1hr to the time before I display it. I've looked at [Calc] and [Formula] with no luck.
Something like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureString]
Measure=String
String=Sat, 13 Jun 13:50

[MeasureTime]
Measure=Time
TimeStamp=[MeasureString]
DynamicVariables=1
TimeStampFormat=%a, %e %b %H:%M

[MeasureTimePlusOne]
Measure=Time
TimeStamp=([MeasureTime:]+3600)
Format=%H:%M
DynamicVariables=1

[MeterTime]
Meter=String
MeasureName=MeasureTimePlusOne
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

1.jpg


So what we are doing is taking that incomplete string that represents a month, day and time (note that it does not contain the year) and use a Time measure with a TimeStamp option to convert that to a numeric timestamp value. It will be based on the Windows EPOCH date of the year 1601, but that doesn't really matter.

Then we add one hour (3600 seconds) to that timestamp value, and use another Time measure to format and display the new time.

Without some more measures, and an assumption about the year, you can't display this with the month, day or year, as you simply can't figure those out based on the incomplete string you are starting with. June 13th is not certain, or even particularly likely, to be on Saturday in an unknown year.


https://docs.rainmeter.net/manual/measures/time/#TimeStamp
https://docs.rainmeter.net/manual/measures/time/#TimeStampFormat
https://docs.rainmeter.net/manual/measures/time/#Format
You do not have the required permissions to view the files attached to this post.
TallShultzy
Posts: 62
Joined: March 30th, 2016, 5:02 pm

Re: Calculation on a string

Post by TallShultzy »

Thanks, I understand. Easy when its pointed out :D
TallShultzy
Posts: 62
Joined: March 30th, 2016, 5:02 pm

Re: Calculation on a string

Post by TallShultzy »

Perhaps not as easy as I thought. What I need to end up with is the string "Sat, 13 Jun 14:50"
If I change Format=%H:%M in [MeasureTimePlusOne] to Format=%a, %e %b %H:%M will I get "Sat, 13 Jun 14:50"
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calculation on a string

Post by jsmorley »

TallShultzy wrote: June 13th, 2020, 4:31 pm Perhaps not as easy as I thought. What I need to end up with is the string "Sat, 13 Jun 14:50"
If I change Format=%H:%M in [MeasureTimePlusOne] to Format=%a, %e %b %H:%M will I get "Sat, 13 Jun 14:50"
Nope.

Time measures must include a year to create a valid timestamp.

I think you will need something like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureString]
Measure=String
String=Sat, 13 Jun 13:50

[MeasureDateStuff]
Measure=String
String=[MeasureString]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(?si)^([\w]+, [\d]+ [\w]+) .*$":"\1"

[MeasureTimeStuff]
Measure=String
String=[MeasureString]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(?si)^[\w]+, [\d]+ [\w]+ (.*)$":"\1"

[MeasureTime]
Measure=Time
TimeStamp=[MeasureTimeStuff]
DynamicVariables=1
TimeStampFormat=%H:%M

[MeasureTimePlusOne]
Measure=Time
TimeStamp=([MeasureTime:]+3600)
Format=%H:%M
DynamicVariables=1

[MeterTime]
Meter=String
MeasureName=MeasureDateStuff
MeasureName2=MeasureTimePlusOne
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=%1 %2

1.jpg


2.jpg



So you just use that incomplete date stuff "as-is", and only manipulate the time with Time measures.

This is going to be a problem at "midnight"... Not sure there is any way to solve that without a valid year as part of the string. You can do some more cheating and assume the year is the "current" year, but I think that only puts off the problem to December 31st.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calculation on a string

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureString]
Measure=String
String=Sat, 13 Jun 13:50

[MeasureYear]
Measure=Time
Format=%Y

[MeasureTime]
Measure=Time
TimeStamp=[MeasureYear], [MeasureString]
DynamicVariables=1
TimeStampFormat=%Y, %a, %d %b %H:%M

[MeasureTimePlusOne]
Measure=Time
TimeStamp=([MeasureTime:]+3600)
Format=%a, %#d %b %H:%M
DynamicVariables=1

[MeterTime]
Meter=String
MeasureName=MeasureTimePlusOne
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
This might work ok... Might be a hiccup on January 1st of the next year, until that string date and time catches up to the year. I hate sites that don't return the year when talking about a date.



1.jpg
You do not have the required permissions to view the files attached to this post.
TallShultzy
Posts: 62
Joined: March 30th, 2016, 5:02 pm

Re: Calculation on a string

Post by TallShultzy »

I'm still getting an error message
Invalid TimeStampFormat: %H:%M (CanalPlan\CanalPlan.ini - [MeasureTime1])
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calculation on a string

Post by jsmorley »

TallShultzy wrote: June 13th, 2020, 5:17 pm I'm still getting an error message
Invalid TimeStampFormat: %H:%M (CanalPlan\CanalPlan.ini - [MeasureTime1])
Be sure you look carefully at what I last posted.

You shouldn't have a TimeStampFormat=%H:%M with that.
TallShultzy
Posts: 62
Joined: March 30th, 2016, 5:02 pm

Re: Calculation on a string

Post by TallShultzy »

Solved it I forgot the "2" in MeasureName2
MeasureName=MeasureDateStuff
MeasureName2=MeasureTimePlusOne

I works.

If I have 6 lines of the RSS feed, do I need to repeat the code 6 times with the measure names changed?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Calculation on a string

Post by jsmorley »

TallShultzy wrote: June 13th, 2020, 5:30 pm Solved it I forgot the "2" in MeasureName2
MeasureName=MeasureDateStuff
MeasureName2=MeasureTimePlusOne

I works.

If I have 6 lines of the RSS feed, do I need to repeat the code 6 times with the measure names changed?
Yessir...