Function Repository Resource:

TwilightTimes

Source Notebook

Compute the starting times for variations of twilight

Contributed by: Jeff Bryant

ResourceFunction["TwilightTimes"][]

computes starting times for available variations of twilight.

ResourceFunction["TwilightTimes"][spec]

computes the starting time for the specified variation spec.

ResourceFunction["TwilightTimes"][spec, loc]

computes the starting time as observed from loc.

ResourceFunction["TwilightTimes"][spec, date]

computes the starting time on date.

ResourceFunction["TwilightTimes"][spec,loc, date]

computes the starting time on date as observed from loc.

Details and Options

Due to unpredictable variations in local atmospheric conditions, actual times may differ from results by one to two minutes.
spec can be any of "EveningAstronomical", "EveningCivil", "EveningNautical", "MorningAstronomical", "MorningCivil", "MorningNautical" or Automatic.
If spec is not provided, a value of Automatic is assumed.
A value of Automatic for spec returns an association of all variants.
If date is not specified, the current date is assumed.
If date is provided, the time zone is inferred from the input date by default.
The same date and time specifications as DateObject can be given.
Results are given on the same day as date.
If loc is not specified, the location is inferred from geo IP lookup.
loc can either be a GeoPosition or an entity that has a "Position" property that returns a GeoPosition.
ResourceFunction["ResourceFunction["TwilightTimes"]"] can accept the following option:
TimeZone$TimeZonetime zone to be used for the dates

Examples

Basic Examples (4) 

Compute the times for all twilight variations for the current date:

In[1]:=
ResourceFunction["TwilightTimes"][]
Out[1]=

Compute the times for a specific twilight variation for the current date:

In[2]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical"]
Out[2]=

Compute the times for a specific twilight variation for a specified date:

In[3]:=
ResourceFunction["TwilightTimes"]["EveningNautical", DateObject[{2021, 6, 21}, TimeZone -> "GMT"]]
Out[3]=

Compute the times for a specific twilight variation for a specified location and date:

In[4]:=
ResourceFunction["TwilightTimes"][GeoPosition[{40.42, -3.69}], DateObject[{2021, 8, 6, 9, 3, 2}, "Instant", "Gregorian", 2.`]]
Out[4]=

Scope (3) 

Compute times for morning twilight:

In[5]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical"]
Out[5]=
In[6]:=
ResourceFunction["TwilightTimes"]["MorningNautical"]
Out[6]=
In[7]:=
ResourceFunction["TwilightTimes"]["MorningCivil"]
Out[7]=

Compute times for evening twilight:

In[8]:=
ResourceFunction["TwilightTimes"]["EveningAstronomical"]
Out[8]=
In[9]:=
ResourceFunction["TwilightTimes"]["EveningNautical"]
Out[9]=
In[10]:=
ResourceFunction["TwilightTimes"]["EveningCivil"]
Out[10]=

Twilight differs depending on the time of year:

In[11]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", DateObject[{2021, 12, 22}]]
Out[11]=
In[12]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", DateObject[{2021, 6, 21}]]
Out[12]=

Dates can be specified in multiple forms:

In[13]:=
ResourceFunction[
 "TwilightTimes"]["MorningAstronomical", "Dec 22, 2021"]
Out[13]=
In[14]:=
ResourceFunction[
 "TwilightTimes"]["MorningAstronomical", {2021, 12, 22}]
Out[14]=
In[15]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", TimeObject[{8}]]
Out[15]=

Locations (2) 

Twilight times differ based on the specified location:

In[16]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", GeoPosition[{0, -90}]]
Out[16]=
In[17]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", GeoPosition[{50, -90}]]
Out[17]=
In[18]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", GeoPosition[{-50, -90}]]
Out[18]=

Locations can be entities:

In[19]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", Entity["City", {"Chicago", "Illinois", "UnitedStates"}]]
Out[19]=

Options (1) 

TimeZone (1) 

Override the default time zone:

In[20]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", DateObject[{2021, 6, 21}, TimeZone -> "GMT"], TimeZone -> -8]
Out[20]=

Possible Issues (1) 

If you go too far north/south, you may end up in a midnight sun or polar night scenario, depending on the time of year, where the Sun never sets within a 24-hour period. In such cases, the results will be missing:

In[21]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", GeoPosition[{90, -90}], DateObject[{2021, 8, 5}]]
Out[21]=
In[22]:=
ResourceFunction["TwilightTimes"]["MorningAstronomical", GeoPosition[{-90, -90}], DateObject[{2021, 8, 5}]]
Out[22]=

Version History

  • 1.1.0 – 24 August 2021

Related Resources

License Information