---
title: "API commands of Sunrise Sunset Timer"
canonical: "https://docs.cuesystem.com/space/CVCAPPLETS/440991768/API%20commands%20of%20Sunrise%20Sunset%20Timer"
format: markdown
---
> Macro (toc)

---

# SetLocation

This function sets the new current coordinates *newlatitude* and *newlongitude* for sunrise and sunset event generation and for calculations by functions *GetSunriseSunset* and *GetDaytimeNightime*. The function returns true on success or false if an error occurs (parameters are out of range).

#### Syntax

```visualbasic
Function SetLocation(
  newlatitude As Double, 
  newlongitude As Double) 
As Long
```

# GetLocation

This function places the current coordinates *latitude* and *longitude* to ByRef parameters.

#### Syntax

```visualbasic
Function GetLocation(
  ByRef latitude As Double, 
  ByRef longitude As Double)
```

# GetLongitude

This function returns the current longitude.

#### Syntax

```visualbasic
Function GetLongitude() As Double
```

# GetLatitude

This function returns the current latitude.

#### Syntax

```visualbasic
Function GetLatitude() As Double
```

# SetZenith

This function sets the *newzenith* for sunrise and sunset event generation and for calculations by the *GetSunriseSunset* and *GetDaytimeNightime* functions. The function returns number COMMAND_OK := -1 on success or ERROR_WRONG_PARAMETERS := 5 if an error occurs (parameter is out of range 90 – 108). You can use following predefined constants such as *newzenith* or any other value in the allowed range:

- ZENITH_OFFICIAL := 90.833
- ZENITH_CIVIL := 96
- ZENITH_NAUTICAL := 102
- ZENITH_ASTRONOMICAL := 108

#### Syntax

```visualbasic
Function SetZenith(newzenith As Double) As Long
```

# GetZenith

This function returns the current zenith for sunrise and sunset event generation and for calculations by the *GetSunriseSunset* and *GetDaytimeNightime* functions.

#### Syntax

```visualbasic
Function GetZenith() As Double
```

# SetEnableEvents

This function enables (*newenableevents* := True) or disables (*newenableevents* := False) the generation of the *OnSunrise* and *OnSunset* events.

#### Syntax

```visualbasic
Function SetEnableEvents(newenableevents As Boolean)
```

# GetEnableEvents

The function returns whether events *OnSunrise* and *OnSunset *are enabled (True) or not (False).

#### Syntax

```visualbasic
Function GetEnableEvents()
```

# GetDaytimeNightimeEx

This function calculates whether it is daytime or nighttime in the place of the given *newlatitude* and *newlongitude*, in UTC time *myutctime. Newzenith *is the desired zenith for daytime – nighttime decision. The function can return the following values:

- IS_DAYTIME       := 1
- IS_NIGHTTIME := 0
- ERROR_FATAL    := 6, in this case the algorithm for sunrise-sunset calculation has failed.

#### Syntax

```visualbasic
Function GetDaytimeNightimeEx (
  newutctime As Time, 
  newlatitude As Double, 
  newlongitude As Double, 
  newzenith As Double) 
As Long
```

# GetDaytimeNighttime

This function calculates whether it is daytime or nighttime in the up-to-date location at the current time. The current zenith is used for daytime – nighttime decision. The function can return the same values as the function *GetDaytimeNightimeEx*.

#### Syntax

```visualbasic
Function GetDaytimeNighttime() As Long
```

# GetSunriseSunsetEx

This function calculates sunrise and sunset times at *newdate* for *newzenith* in the location given by *newlatitude* and *newlongitude*. Sunrise and sunset times are placed to ByRef parameters *sunriseutc* and *sunsetutc*. Results are in UTC time. The function can return the following values:

- COMMAND_OK := - 1 in case of success and there are both sunrise and sunset in given conditions
- EXCEPTION_PERMANENT_DAY := 1 (in polar areas it is permanent day)
- EXCEPTION_PERMANENT_NIGHT := 2 (in polar areas it is permanent night)
- EXCEPTION_SUNRISE_ONLY := 3 (in polar areas sunrise occurs only at the given date)
- EXCEPTION_SUNSET_ONLY := 4 (in polar areas sunset occurs only at the given date)
- ERROR_WRONG_PARAMETERS := 5, in case that

#### Syntax

```visualbasic
Function GetSunriseSunsetEx(
  newdate As Time, 
  newlatitude As Double, 
  newlongitude As Double, 
  newzenith As Double, 
  ByRef sunriseutc As Time, 
  ByRef sunsetutc As Time) 
As Long
```

*newlatitude*, *newlongitude* or *newzenith* are out of limits

- ERROR_WRONG_TIME := 7, if

*newdate* is out of limits

- ERROR_FATAL := 6, in this case the algorithm for sunrise-sunset calculation has failed.

# GetSunriseSunset

This function calculates sunrise and sunset times for the current day in the up-to-date latitude and longitude and for currrent zenith. Results are in UTC time. The function can return the same values as the function *GetSunriseSunsetEx*.

#### Syntax

```visualbasic
Function GetSunriseSunset(
  ByRef sunriseutc As Time, 
  ByRef sunsetutc As Time) 
As Long
```

# GetCurrentLocalToUTCTimeDifference

All calculations and results in SunriseSunsetTimer must be in UTC time, because it is the only “standard” time without any jumps and discontinuities. If you need to convert UTC time to your local time, this function can help you. This function returns the current difference between local and UTC time (rounded to 15 minutes): GetCurrentLocalToUTCTimeDifference := GetLocalTime() - GetUTCTime()

#### Syntax

```visualbasic
Function GetCurrentLocalToUTCTimeDifference() As Time
```

You can use the value obtained by this function to convert UTC time results to your local time:

*local_time_result := UTC_time_result + GetCurrentLocalToUTCTimeDifference().*

Do not forget that this value is valid only at the moment of performing this function and on the dates in which summer and winter time are changed it can be different at the beginning and at the end of the day.