I'm updating my sun/moon/prayer time skins so that the user can search for his/her location with http://wxdata.weather.com/wxdata/search/search?where=#SearchLocation# and it will return the latitude, longitude and time zone of the #SearchLocation#
The problem is that what is returned by wxdata.weather.com is not always the correct time zone. Check Istanbul and New Delhi as current examples.
So I tiddled around with various options but still found http://wxdata.weather.com/wxdata/search/search?where=#SearchLocation# to be the most user friendly way to get a #WeatherCode# that could be used to grab the latitude and longitude of a location using http://wxdata.weather.com/wxdata/weather/local/#WeatherCode#.
So after a little more thought = glasses of wine, it came to me that I don't actually need the time zone of the #SearchLocation# but rather the difference in time between my OS and the time returned when I get the latitude and longitude of the search location using http://wxdata.weather.com/wxdata/weather/local/#WeatherCode#.
So, if the time returned by <tm>(.*)</tm> from http://wxdata.weather.com/wxdata/weather/local/#WeatherCode# is 4:21 PM and the time on my OS is 12:21 (24 hour clock) how and what do I use to calculate the difference (-4 hr)? Note that anything to the nearest 30 minutes is good enough.
I'm only marginally better with RegExp than I am with Timestamp so any and all suggestions would be welcome. Thanks in advance.
It is currently April 20th, 2024, 5:44 am
Getting time differences with RegExp / Timestamp
-
- Posts: 1171
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Getting time differences with RegExp / Timestamp
Could you please post the code you have so far? Because I'm trying to use the posted URLs, but can't get nor latitude and longitude, nor the time zone, just the weather code of the entered location. I'd be curious how do you get those information. Here just mention that I am interested into this not just to can answer you, but also for another skin of mine, I'm working with. But with a somehow working code, I probably would deliver some solution (I hope!).
-
- Rainmeter Sage
- Posts: 2604
- Joined: March 23rd, 2015, 5:26 pm
Re: Getting time differences with RegExp / Timestamp
Well, sir, I've actually taken your sun/moon Lua scripts and modified them very slightly to do exactly as you suggest to create my Weather skin. (See my Gadgets link in my sig if you want the whole code.) I used your code to calculate sun and moon rise/set times.Mordasius wrote: ↑November 2nd, 2018, 5:38 pmSo after a little more thought = glasses of wine, it came to me that I don't actually need the time zone of the #SearchLocation# but rather the difference in time between my OS and the time returned when I get the latitude and longitude of the search location using http://wxdata.weather.com/wxdata/weather/local/#WeatherCode#.
So, if the time returned by <tm>(.*)</tm> from http://wxdata.weather.com/wxdata/weather/local/#WeatherCode# is 4:21 PM and the time on my OS is 12:21 (24 hour clock) how and what do I use to calculate the difference (-4 hr)? Note that anything to the nearest 30 minutes is good enough.
I'm only marginally better with RegExp than I am with Timestamp so any and all suggestions would be welcome. Thanks in advance.
Basically, you'll need a Time measure to grab your local time without any DST (so the UTC conversion works properly).
Code: Select all
[MeasureLocalTime]
Measure=Time
TimeZone=local
DaylightSavingTime=0
nTimeZone = the tz bias from TWC (includes any DST offset from UTC)
nLocalTz = this is YOUR tz bias from UTC
nTimestamp = the Windows timestamp from your Time measure
Code: Select all
local nLocalTz = (getTimeOffset() / 3600)
if nTimeZone == nLocalTz then
tDate = os.date("!*t", nTimestamp)
else
tDate = os.date("!*t", nTimestamp - getTimeOffset() + (nTimeZone * 3600))
end
-- convert Windows timestamp (0 = 1/1/1601) to Unix/Lua timestamp (0 = 1/1/1970)
tDate.year = tDate.year - (1970 - 1601)
....
function getTimeOffset()
return (os.time() - os.time(os.date('!*t')) + (os.date('*t')['isdst'] and 3600 or 0))
end
I found your Lua and skins super helpful and educational, so I hope I am able to return the favor!
-
- Posts: 1171
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting time differences with RegExp / Timestamp
Apologies for the delay in replying.
So the problem I have is that weather.com is not always providing correct time zone information and I can't find a better source of latitute, longitude and timezone that can be easily searched/scraped without an API.
I'm still playing around with the skins but while both the time of reporting and reported time zone are wrong it is impossible to use the data in a skin calculating sun and moon times.
Yup.. that's what I was doing but I was scuppered by Weather.com which provides accurate Latitude and Longitude but sometimes gives dubious Time Zone data. Take a look at http://wxdata.weather.com/wxdata/weather/local/TUXX0014?cc=*&unit=C&dayf=4 which suggests the TimeZone for Istanbul is +2 GMT. It should be +3 GMT if you check with Google or https://www.timeanddate.com/time/zone/turkey/istanbul. I use www.timeanddate.com as my reference for sun and moon times and it gives results very close to the sunmoon.lua scripts I use.SilverAzide wrote: ↑November 2nd, 2018, 10:09 pm Basically, you'll need a Time measure to grab your local time without any DST (so the UTC conversion works properly).
So the problem I have is that weather.com is not always providing correct time zone information and I can't find a better source of latitute, longitude and timezone that can be easily searched/scraped without an API.
Try this http://wxdata.weather.com/wxdata/weather/local/TUXX0014?cc=*&unit=C&dayf=4 And note that, as above, while the Latitude and longitude are correct, the <zone>(.*)</zone> and <tm>(.*)</tm> are both wrong (as compared with www.timeanddate.com).
I'm still playing around with the skins but while both the time of reporting and reported time zone are wrong it is impossible to use the data in a skin calculating sun and moon times.
-
- Rainmeter Sage
- Posts: 16147
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Getting time differences with RegExp / Timestamp
Well, I thought there is a way to get the coordinates and the time zone from the search results (http://wxdata.weather.com/wxdata/search/search?where=#SearchLocation#). I know how to get them from the set up location page (http://wxdata.weather.com/wxdata/weather/local/TUXX0014?cc=*&unit=C&dayf=4). This is clear.Mordasius wrote: ↑November 3rd, 2018, 6:07 pm Try this http://wxdata.weather.com/wxdata/weather/local/TUXX0014?cc=*&unit=C&dayf=4 And note that, as above, while the Latitude and longitude are correct, the <zone>(.*)</zone> and <tm>(.*)</tm> are both wrong (as compared with www.timeanddate.com).
I'm still playing around with the skins but while both the time of reporting and reported time zone are wrong it is impossible to use the data in a skin calculating sun and moon times.
However I'm not sure I get that difference. For me everything looks to be all right. Am I wrong somewhere?
-
- Posts: 1171
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting time differences with RegExp / Timestamp
The problem is that the wrong TimeZone is returned for places like New Delhi (http://wxdata.weather.com/wxdata/weather/local/INXX0096?cc=*&unit=C&dayf=4 ). wxdata gives the TimeZone as +5 when the actual TimeZone for New Delhi is +5.5.
The following skin corrects the TimeZone for most places but still doesn't work for places like Kathmandu (WeatherCode=NPXX0002) where wxdata gives +5, my skin gives +6 and the actual TimeZone is +5.75. This may seem like a small difference but it throws the times for moonrise, moonset, sunrise and sunset off by quite a few minutes and sometimes hours.
Code: Select all
[Rainmeter]
AccurateText=1
MiddleMouseUPAction=!Refresh
[Variables]
; WeatherCode=USHI0026
; WeatherCode=USCA0638
; WeatherCode=CAXX0420
; WeatherCode=USFL0481
; WeatherCode=UKXX0085
; WeatherCode=TUXX0014
WeatherCode=INXX0096
; WeatherCode=NPXX0002
; WeatherCode=ASXX0001
; WeatherCode=NZXX0003
;----------------------------------------
[sText]
FontColor=eeeeee
SolidColor=111111
X=15
AntiAlias=1
[MtPanelBack]
Meter=Shape
Shape=Rectangle 0,0, 180, 140 , 18 | StrokeWidth 0 | Fill Color 111111
AntiAlias=1
UpdateDivider=-1
; ----- WXData -----#WeatherCode# obtained from a search using
; http://wxdata.weather.com/wxdata/search/search?where=#SearchLocation#
[mWeatherData]
Measure=WebParser
Url=http://wxdata.weather.com/wxdata/weather/local/#WeatherCode#?cc=*&unit=C&dayf=4
UpdateRate=120
RegExp=(?siU)^(.*)$
FinishAction=[!EnableMeasureGroup LocTime][!UpdateMeasureGroup LocTime] [!UpDateMeter MtWeatherDataSet] [!ShowMeter MtWeatherDataSet]
[mWeatherDataLocation]
Measure=WebParser
URL=[mWeatherData]
RegExp=(?siU)<loc id="(.*)".*<dnam>(.*),.*</dnam>.*<tm>(.*)</tm>.*<lat>(.*)</lat>.*<lon>(.*)</lon>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<zone>(.*)</zone>.*</loc>.*<lsup>(.*)</lsup>
Group=LocTime
Disabled=1
[mLocationName]
Measure=WebParser
URL=[mWeatherDataLocation]
StringIndex=2
Group=LocTime
Disabled=1
[mTimeAtLocation]
Measure=WebParser
URL=[mWeatherDataLocation]
StringIndex=3
Group=LocTime
Disabled=1
[mLocHours]
Measure=Time
TimeStamp=[mTimeAtLocation]
TimeStampFormat=%I:%M %p
Format=%H hrs
Group=LocTime
Disabled=1
DynamicVariables=1
[mLocMinutes]
Measure=Time
TimeStamp=[mTimeAtLocation]
TimeStampFormat=%I:%M %p
Format=%M mins
Group=LocTime
Disabled=1
DynamicVariables=1
[mWeatherTimeZone]
Measure=WebParser
URL=[mWeatherDataLocation]
StringIndex=8
Group=LocTime
Disabled=1
[mWeatherDate]
Measure=WebParser
URL=[mWeatherDataLocation]
RegExp=(?siU)(.*)\s
StringIndex=9
[mLocDate]
Measure=Time
TimeStamp=[&mWeatherDate]
TimeStampFormat= %#m/%d/%y
Group=LocTime
Disabled=1
DynamicVariables=1
; ----- additional measures -----
[mGMTtime]
Measure=Time
TimeZone=0
[mLocalTime]
Measure=Time
[mLocalTimeZone]
Measure=Calc
Formula=( mLocalTime -mGMTTime )/3600
[mLocalHours]
Measure=Time
Format=%#H
[mLocalMinutes]
Measure=Time
Format=%#M
[mLocalTimeNow]
Measure=Calc
Formula=(( ( mLocalHours *3600)+ ( mLocalMinutes *60) )/3600)
[mLocationTimeNow]
;-- add 5 minutes to account for delayed reporting
Measure=Calc
Formula=(( ( mLocHours *3600)+ ( (mLocMinutes+5) *60) )/3600)
DynamicVariables=1
[mSameDay]
Measure=Calc
Formula= ((( mLocalTime - mLocDate )/3600)-24) > 0? 48 : 0
DynamicVariables=1
[mLocationTimeZone]
Measure=Calc
Formula= mLocalTimeNow > mLocationTimeNow ? Round(( (mLocalTimeZone*2)-(Trunc(mLocalTimeNow*2)-Trunc(mLocationTimeNow*2)- (mSameDay)))/2,1) : Round(( (mLocalTimeZone*2)+(Trunc(mLocationTimeNow*2)-Trunc(mLocalTimeNow*2)- (mSameDay)))/2,1)
Group=LocTime
Disabled=1
;-----------------------------------------------------------------
[MtTitle]
Meter=String
MeterStyle=sText
Y=30
Text=Fetching data.....
[MtWeatherDataSet]
Meter=String
MeterStyle=sText
Y=-15R
Text=Location: [mLocationName]#CRLF#Time: [mTimeAtLocation]#CRLF#Weather Time Zone: [mWeatherTimeZone]#CRLF#--------------------#CRLF#Calc Time Zone: [mLocationTimeZone]
DynamicVariables=1
Hidden=1
I'm still playing around to get the TimeZone to the closest 15 minutes but that is tricky when the time or reporting from wxdata.weather.com can be 5-15 minutes earlier than the actual time at the location. I'll probably have to go off to another site to get the time at the location but I was trying to avoid that.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting time differences with RegExp / Timestamp
I find https://www.timeanddate.com/ to be a pretty nice one-stop-shop for world times.
https://www.timeanddate.com/worldclock/nepal/kathmandu
https://www.timeanddate.com/worldclock/nepal/kathmandu
-
- Posts: 1171
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting time differences with RegExp / Timestamp
Yup. www.timeanddate.com is what I use to check all my sun and moon skins. But is there any easy way to let a skin user just type in his/her location and then select the location from a list of likely places like we can do with http://wxdata.weather.com/wxdata/search/search?where=SearchLocation ?jsmorley wrote: ↑November 4th, 2018, 11:58 am I find https://www.timeanddate.com/ to be a pretty nice one-stop-shop for world times.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting time differences with RegExp / Timestamp
https://www.timeanddate.com/worldclock/results.html?query=kathmandu maybe...Mordasius wrote: ↑November 4th, 2018, 12:07 pm Yup. www.timeanddate.com is what I use to check all my sun and moon skins. But is there any easy way to let a skin user just type in his/her location and then select the location from a list of likely places like we can do with http://wxdata.weather.com/wxdata/search/search?where=SearchLocation ?
-
- Posts: 1171
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting time differences with RegExp / Timestamp
Looks promising but a fair amount of scraping would be needed. Something to play with though...jsmorley wrote: ↑November 4th, 2018, 12:11 pm https://www.timeanddate.com/worldclock/results.html?query=kathmandu maybe...