[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

solar local time

Ara.T.Howard

8/8/2006 6:23:00 PM

13 Answers

Logan Capaldo

8/8/2006 6:46:00 PM

0


On Aug 8, 2006, at 2:23 PM, ara.t.howard@noaa.gov wrote:

>
> i'm working on a sticky issue: i'm converting some times based on
> a utc time
> and longitude - the goal is the express the time as solar local time.
>
> the code i have is close. it does something like:
>
>
> DEG_PER_HR = 15.0
> SECS_PER_MIN = 60.0
> SECS_PER_HR = SECS_PER_MIN * 60.0
> SECS_PER_DAY = SECS_PER_HR * 24
>
> # longitudes > 180 degrees are behind UT
> # longitudes <= 180 degrees are ahead of UT
>
> offset_seconds =
> if longitude > 180.0
> - ((360.0 - longitude) / DEG_PER_HR) * SECS_PER_HR
> else
> (longitude / DEG_PER_HR) * SECS_PER_HR
> end
>
> utc + offset_seconds
>
>
> this in fact yields the correct time __except__ that's it's
> expressed in zulu
> time and not the 'local' time zone. the trick is that 'local' here
> means
> 'there' not 'here'! ;-) in otherwords it needs to be expressed in
> the local
> time zone of that __longitude__ not mine and not that of greenwich.
>
> to put it more consisely i need to be able to follow
>
> locatime_but_in_utc = utc + offset_seconds
>
> with
>
> move_to_zone locatime_but_in_utc, longitude
>
> or some other viable alternative.
>
> thoughts?
>
>
Does TZInfo bring you closer?
Stolen from the README:

> Example usage
>
> To convert a time in UTC to a local time in the America/New_York
> timezone, you can do the following:
>
> require_gem 'tzinfo'
> include TZInfo
>
> tz = Timezone.get('America/New_York')
> local = tz.utc_to_local(Time.utc(2005,8,29,15,35,0))
>
> Note that the Time returned will look like it is UTC (Time.zone
> will return "UTC"). This is because it is not currently possible to
> change the offset of an individual Time instance.


> -a
> --
> to foster inner awareness, introspection, and reasoning is more
> efficient than
> meditation and prayer.
> - h.h. the 14th dali lama
>


Ara.T.Howard

8/8/2006 7:18:00 PM

0

Ara.T.Howard

8/8/2006 7:19:00 PM

0

Tim Pease

8/8/2006 7:23:00 PM

0

On 8/8/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>
> i'm working on a sticky issue: i'm converting some times based on a utc time
> and longitude - the goal is the express the time as solar local time.
>
> the code i have is close. it does something like:
>
>
> DEG_PER_HR = 15.0
> SECS_PER_MIN = 60.0
> SECS_PER_HR = SECS_PER_MIN * 60.0
> SECS_PER_DAY = SECS_PER_HR * 24
>
> # longitudes > 180 degrees are behind UT
> # longitudes <= 180 degrees are ahead of UT
>
> offset_seconds =
> if longitude > 180.0
> - ((360.0 - longitude) / DEG_PER_HR) * SECS_PER_HR
> else
> (longitude / DEG_PER_HR) * SECS_PER_HR
> end
>
> utc + offset_seconds
>
>
> this in fact yields the correct time __except__ that's it's expressed in zulu
> time and not the 'local' time zone. the trick is that 'local' here means
> 'there' not 'here'! ;-) in otherwords it needs to be expressed in the local
> time zone of that __longitude__ not mine and not that of greenwich.
>
> to put it more consisely i need to be able to follow
>
> locatime_but_in_utc = utc + offset_seconds
>
> with
>
> move_to_zone locatime_but_in_utc, longitude
>
> or some other viable alternative.
>
> thoughts?
>

ZONES = class << Time; ZoneOffset.keys.map {|x| x.length == 1 ? x :
nil}.compact.sort; end
ZONES.unshift ZONES.pop

def move_to_zone( utc, longitude )
zone = ZONES[Integer(longitude) / Integer(DEG_PER_HR)]
utc - Time.zone_offset(zone)
end


This does not take into account daylight savings, etc. But give it a
shot and see if it's what you need.

TwP

Tim Pease

8/8/2006 7:40:00 PM

0

On 8/8/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>

snip

>
> this in fact yields the correct time __except__ that's it's expressed in zulu
> time and not the 'local' time zone. the trick is that 'local' here means
> 'there' not 'here'! ;-) in otherwords it needs to be expressed in the local
> time zone of that __longitude__ not mine and not that of greenwich.
>
> to put it more consisely i need to be able to follow
>
> locatime_but_in_utc = utc + offset_seconds
>
> with
>
> move_to_zone locatime_but_in_utc, longitude
>

Clarification question ... do you want the returned value to be a
Float or an actual Time object?

TwP

PS Maybe I should have asked this before posting my little solution there :/

Ara.T.Howard

8/8/2006 9:20:00 PM

0

Ara.T.Howard

8/8/2006 9:21:00 PM

0

Morton Goldberg

8/8/2006 9:57:00 PM

0

If I understand the problem you describe (likelihood estimate ~ 50%),
it's similar to a telemetry data problem I once worked on. Here is
how I handled it:

1. express the local solar time value of interest in seconds from
local midnight
2. convert the UTC time stamp to seconds from UTC midnight
3. longitude shift the result of 2 to the local time frame
4. compare result of 1 and 3 to determine whether or not to process
further

Maybe you could adopt a similar approach.

Regards, Morton

On Aug 8, 2006, at 2:23 PM, ara.t.howard@noaa.gov wrote:

>
> i'm working on a sticky issue: i'm converting some times based on
> a utc time
> and longitude - the goal is the express the time as solar local time.
>
> the code i have is close. it does something like:
>
>
> DEG_PER_HR = 15.0
> SECS_PER_MIN = 60.0
> SECS_PER_HR = SECS_PER_MIN * 60.0
> SECS_PER_DAY = SECS_PER_HR * 24
>
> # longitudes > 180 degrees are behind UT
> # longitudes <= 180 degrees are ahead of UT
>
> offset_seconds =
> if longitude > 180.0
> - ((360.0 - longitude) / DEG_PER_HR) * SECS_PER_HR
> else
> (longitude / DEG_PER_HR) * SECS_PER_HR
> end
>
> utc + offset_seconds
>
>
> this in fact yields the correct time __except__ that's it's
> expressed in zulu
> time and not the 'local' time zone. the trick is that 'local' here
> means
> 'there' not 'here'! ;-) in otherwords it needs to be expressed in
> the local
> time zone of that __longitude__ not mine and not that of greenwich.
>
> to put it more consisely i need to be able to follow
>
> locatime_but_in_utc = utc + offset_seconds
>
> with
>
> move_to_zone locatime_but_in_utc, longitude
>
> or some other viable alternative.
>
> thoughts?
>
>
> -a
> --
> to foster inner awareness, introspection, and reasoning is more
> efficient than
> meditation and prayer.
> - h.h. the 14th dali lama
>


Ara.T.Howard

8/8/2006 10:27:00 PM

0

Ara.T.Howard

8/8/2006 10:43:00 PM

0