Skip to content

Commit

Permalink
Merge pull request #79 from observerly/feature/temporal/convertLocalS…
Browse files Browse the repository at this point in the history
…iderealTimeToGreenwhichSiderealTime

feat: Added convertLocalSiderealTimeToGreenwhichSiderealTime() to temporal module in @observerly/astrometry.
  • Loading branch information
michealroberts authored Aug 28, 2023
2 parents 0dc7cf4 + b4b1fd9 commit f3bdd67
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/temporal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@

/*****************************************************************************************************************/

export {}
import { type GeographicCoordinate } from './common'

/*****************************************************************************************************************/

/**
*
* convertLocalSiderealTimeToGreenwhichSiderealTime()
*
* Makes the conversion from Greenwich Sidereal Time to Local Sidereal Time.
*
* @param LST - a given Local Sidereal Time
* @param observer - The geographic coordinate of the observer.
* @returns GST - the Greenwich Sidereal Time for the given Local Sidereal Times
*
*/
export const convertLocalSiderealTimeToGreenwhichSiderealTime = (
LST: number,
observer: GeographicCoordinate
): number => {
const { longitude } = observer

let GST = LST - longitude / 15.0

if (GST < 0) {
GST += 24
}

if (GST > 24) {
GST -= 24
}

return GST
}

/*****************************************************************************************************************/
47 changes: 47 additions & 0 deletions tests/temporal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @package @observerly/astrometry/temporal
// @license Copyright © 2021-2023 observerly

/*****************************************************************************************************************/

import { describe, expect, it } from 'vitest'

/*****************************************************************************************************************/

import {
getLocalSiderealTime,
getGreenwhichSiderealTime,
convertLocalSiderealTimeToGreenwhichSiderealTime
} from '../src'

/*****************************************************************************************************************/

// For testing we need to specify a date because most calculations are
// differential w.r.t a time component. We set it to the author's birthday:
export const datetime = new Date('2021-05-14T00:00:00.000+00:00')

// For testing we will fix the latitude to be Manua Kea, Hawaii, US
export const latitude = 19.820611

// For testing we will fix the longitude to be Manua Kea, Hawaii, US:
export const longitude = -155.468094

/*****************************************************************************************************************/

describe('convertLocalSiderealTimeToGreenwhichSiderealTime', () => {
it('should be defined', () => {
expect(convertLocalSiderealTimeToGreenwhichSiderealTime).toBeDefined()
})

it('should return the correct Local Sidereal Time for a given Greenwich Sidereal Time', () => {
const LST = getLocalSiderealTime(datetime, longitude)
const GST = getGreenwhichSiderealTime(datetime)
expect(
convertLocalSiderealTimeToGreenwhichSiderealTime(LST, { latitude, longitude })
).toBeCloseTo(GST)
})
})

/*****************************************************************************************************************/

0 comments on commit f3bdd67

Please sign in to comment.