It is currently March 29th, 2024, 9:30 am

Timestamp Help

Get help with creating, editing & fixing problems with skins
bora12
Posts: 13
Joined: August 9th, 2016, 4:24 pm

Timestamp Help

Post by bora12 »

Let's assume the current hour is 11, I would like to output a timestamp like this:
1/9/2019 12:19:19
which is just adding an hour to the current time. Instead I get this:
1/9/2019 00:19:19

Thank you in advance.

Code: Select all

[Variables]
mm_ss=19:19

[MeasureNowDate]
Measure=Time
Format=%#m/%#d/%Y

[MeasureNowH]
Measure=Time
Format=%#H

[MeasureNowHPlus]
Measure=Calc
Formula=MeasureNowH+1

[MeasureThen]
Measure=Time
[b]TimeStamp=[MeasureNowDate] [MeasureNowHPlus]:#mm_ss#[/b]
TimeStampFormat=%#m/%#d/%Y %#H:%M:%S
Format=%#m/%#d/%Y %H:%M:%S
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Timestamp Help

Post by balala »

bora12 wrote: January 9th, 2019, 7:42 pm Let's assume the current hour is 11, I would like to output a timestamp like this:
1/9/2019 12:19:19
which is just adding an hour to the current time. Instead I get this:
1/9/2019 00:19:19
Don't do this way. You need an extremely simple Time measure, with no Format set and that one will be used into the TimeStamp option of the [MeasureThen] measure. So, first add a this kind of Time measure:

Code: Select all

[MeasureTime]
Measure=Time
Then use this measure's numeric value (be careful, because a Time measure has completely different string and numeric values - see below) into the TimeStamp option of the "final" Time measure:

Code: Select all

[MeasureThen]
Measure=Time
TimeStamp=([MeasureTime:]+3600)
Format=%#m/%#d/%Y %H:#mm_ss#
DynamicVariables=1
See that here I added one hour (so 3600 seconds) to the numeric value returned by the previously added [MeasureTime] measure: TimeStamp=([MeasureTime:]+3600). In this expression [MeasureTime:] is the numeric value of the [MeasureTime] measure (and using this, makes to must have to add the DynamicVariables=1 option to the measure as well) and there is added 3600. Also see that I set a Format for this option and into this Format as minutes and seconds I added the previously defined #mm_ss# variable.
Along with all this, your code looks in the following form:

Code: Select all

[Variables]
mm_ss=19:19

[MeasureTime]
Measure=Time

[MeasureNowDate]
Measure=Time
Format=%#m/%#d/%Y

[MeasureNowH]
Measure=Time
Format=%#H

[MeasureNowHPlus]
Measure=Calc
Formula=MeasureNowH+1

[MeasureThen]
Measure=Time
TimeStamp=([MeasureTime:]+3600)
Format=%#m/%#d/%Y %H:#mm_ss#
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Timestamp Help

Post by jsmorley »

One thing I would note is that it is probably not good to get in the habit of using [TimeMeasureName:] to obtain or modify the timestamp value of a Time measure. That can get tricky depending on what you have as the Format option on the Time measure. If there is no Format option, it will return the timestamp as the number value, but if there is one, like Format=%H:%M or some such, then the number value will be the best it can figure out as the numeric value of the value returned by the format, or more likely zero.

In the case of Format=%H:%M, that may for instance return a string of 12:32, which cannot be treated as a valid numeric value, and the number value of the measure will be zero.

You will basically NEVER get the correct result if there is ANY Format option on the Time measure.

It's better to always use [TimeMeasureName:Timestamp] to get the timestamp value of a Time measure as a section variable.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Timestamp Help

Post by balala »

jsmorley wrote: January 9th, 2019, 8:33 pm One thing I would note is that it is probably not good to get in the habit of using [TimeMeasureName:] to obtain or modify the timestamp value of a Time measure. That can get tricky depending on what you have as the Format option on the Time measure. If there is no Format option, it will return the timestamp as the number value, but if there is one, like Format=HH:MM or some such, then the number value will be the best it can figure out as the numeric value of the value returned by the format, or more likely zero.

In the case of Format=HH:MM, that may for instance return a string of 12:32, which cannot be treated as a valid numeric value, and the number value of the measure will be zero.

You will basically NEVER get the correct result if there is ANY Format option on the Time measure.

It's better to always use [TimeMeasureName:Timestamp] to get the timestamp value of a Time measure as a section variable.
Not sure how this could be used to achieve what bora12 asked for. Could you please post a sample code?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Timestamp Help

Post by jsmorley »

balala wrote: January 9th, 2019, 8:40 pm Not sure how this could be used to achieve what bora12 asked for. Could you please post a sample code?
All I'm suggesting is that I would be inclined to use:

Code: Select all

[MeasureThen]
Measure=Time
TimeStamp=([MeasureTime:Timestamp]+3600)
Format=%#m/%#d/%Y %H:#mm_ss#
DynamicVariables=1
In this particular case, since MeasureTime has no Format option on it, it doesn't matter, but I contend that it is a good practice to get into.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Timestamp Help

Post by balala »

jsmorley wrote: January 9th, 2019, 9:18 pm but I contend that it is a good practice to get into.
And what would be the best practice?
Because with both [MeasureThen] measures (yours and mine) I get the same result and no error messages int he log.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Timestamp Help

Post by jsmorley »

What I'm saying is that it's a bit like using "quotes" around string parameters in bangs. They are not always needed, but it's a good habit to get into, as it will save head-scratching at some point sooner or later.

If you look at this:

Code: Select all

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

[TimeMeasure1]
Measure=Time

[TimeMeasure2]
Measure=Time
Format=%A, %B %#d, %Y %#I:%M %p

[MeasureTimeStamp1]
Measure=Calc
Formula=[TimeMeasure1:]
DynamicVariables=1

[MeasureTimeStamp2]
Measure=Calc
Formula=[TimeMeasure2:]
DynamicVariables=1

[MeterOne]
Meter=String
1.jpg

Note that the numeric value of TimeMeasure1, which has no Format option on it, is in fact the correct timestamp for the current time. The numeric value of TimeMeasure2 on the other hand, which has a Format option, is ZERO. In order to get the timestamp value in that case, you would use [TimeMeasure2:Timestamp] in a formula, and not [TimeMeasure2:] which will return zero.

If I just ALWAYS do that, then I get the correct timestamp value no matter what the Format option is set to:

Code: Select all

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

[TimeMeasure1]
Measure=Time

[TimeMeasure2]
Measure=Time
Format=%A, %B %#d, %Y %#I:%M %p

[MeasureTimeStamp1]
Measure=Calc
Formula=[TimeMeasure1:Timestamp]
DynamicVariables=1

[MeasureTimeStamp2]
Measure=Calc
Formula=[TimeMeasure2:Timestamp]
DynamicVariables=1

[MeterOne]
Meter=String
2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Timestamp Help

Post by balala »

jsmorley wrote: January 9th, 2019, 9:32 pm Note that the numeric value of TimeMeasure1, which has no Format option on it, is in fact the correct timestamp for the current time. The numeric value of TimeMeasure2 on the other hand, which has a Format option, is ZERO. In order to get the timestamp value in that case, you would use [TimeMeasure2:Timestamp] in a formula, and not [TimeMeasure2:] which will return zero.

If I do that, then I get the correct timestamp value no matter what the Format option is set to:
:jawdrop :o
Now I think I'm starting to realize what's going on (I hope, but I'm not sure!). A while ago I replied to xenium on a similar topic and suggested him to remove the Format option of a Time measure, to can use the measure into the TimeStamp option of another Time measure. Now I see my mistake. :?
Thank you. :bow: I again understood something new (to me).
There is always something to learn with Rainmeter. :great:
I'm very grateful to you. Again.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Timestamp Help

Post by jsmorley »

The rules for the Time measure are like this:

1) If there is no Format option on a Time measure, the string value will be the result of the default %H:%M:%S and the numeric value will be the Windows timestamp.

2) If there is ANY Format option on a Time measure, the string value will be the result of the formatting code(s) used and the number value will be the number returned by the format IF that is a valid number, like Format=%#H for instance, or ZERO if the Format is not a valid number like Format=%H:%M:%S. It will NEVER return a timestamp number if there is any Format option.

3) If you use a Time measure in a section variable as [MeasureName:] it will return the number value. That MIGHT be a timestamp, or it might be a number that has nothing to do with the timestamp, or most likely, it will be ZERO.

4) If you use a Time measure in a section variable as [MeasureName:Timestamp] it will return the timestamp value. It will ALWAYS return the timestamp value, no matter what any Format option is set to.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Timestamp Help

Post by balala »

jsmorley wrote: January 9th, 2019, 9:54 pm The rules for the Time measure are like this:

1) If there is no Format option on a Time measure, the string value will be the result of the default %HH:%MM:%SS and the numeric value will be the Windows timestamp.

2) If there is ANY Format option on a Time measure, the string value will be the result of the formatting code(s) used and the number value will be the number returned by the format IF that is a valid number, like Format=%#H for instance, or ZERO if the Format is not a valid number like Format=%HH:%MM:%SS. It will NEVER return a timestamp number if there is any Format option.

3) If you use a Time measure in a section variable as [MeasureName:] it will return the number value. That MIGHT be a timestamp, or it might be a number that has nothing to do with the timestamp, or most likely, it will be ZERO.

4) If you use a Time measure in a section variable as [MeasureName:Timestamp] it will return the timestamp value. It will ALWAYS return the timestamp value, no matter what any Format option is set to.
Thanks for these details. I'll have to keep in my mind and will have to re-read them all over again and again.