It is currently May 8th, 2024, 4:07 am
Calculation on a string
-
- Posts: 62
- Joined: March 30th, 2016, 5:02 pm
Calculation on a string
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.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculation on a string
Something like this: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.
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
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.
-
- Posts: 62
- Joined: March 30th, 2016, 5:02 pm
Re: Calculation on a string
Thanks, I understand. Easy when its pointed out
-
- Posts: 62
- Joined: March 30th, 2016, 5:02 pm
Re: Calculation on a string
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"
If I change Format=%H:%M in [MeasureTimePlusOne] to Format=%a, %e %b %H:%M will I get "Sat, 13 Jun 14:50"
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculation on a string
Nope.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"
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
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.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculation on a string
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
You do not have the required permissions to view the files attached to this post.
-
- Posts: 62
- Joined: March 30th, 2016, 5:02 pm
Re: Calculation on a string
I'm still getting an error message
Invalid TimeStampFormat: %H:%M (CanalPlan\CanalPlan.ini - [MeasureTime1])
Invalid TimeStampFormat: %H:%M (CanalPlan\CanalPlan.ini - [MeasureTime1])
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculation on a string
Be sure you look carefully at what I last posted.TallShultzy wrote: ↑June 13th, 2020, 5:17 pm I'm still getting an error message
Invalid TimeStampFormat: %H:%M (CanalPlan\CanalPlan.ini - [MeasureTime1])
You shouldn't have a TimeStampFormat=%H:%M with that.
-
- Posts: 62
- Joined: March 30th, 2016, 5:02 pm
Re: Calculation on a string
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?
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?
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculation on a string
Yessir...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?