From b4b1fd9d519a5e2a29cfdf5c042c5b61ae950109 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" <84131395+michealroberts@users.noreply.github.com> Date: Mon, 28 Aug 2023 16:29:39 +0100 Subject: [PATCH] feat: Added convertLocalSiderealTimeToGreenwhichSiderealTime() to temporal module in @observerly/astrometry. feat: Added convertLocalSiderealTimeToGreenwhichSiderealTime() to temporal module in @observerly/astrometry. Includes associated test suite and expected API output. --- src/temporal.ts | 34 +++++++++++++++++++++++++++++- tests/temporal.spec.ts | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/temporal.spec.ts diff --git a/src/temporal.ts b/src/temporal.ts index 9d3392d..ac4e8de 100644 --- a/src/temporal.ts +++ b/src/temporal.ts @@ -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 +} /*****************************************************************************************************************/ diff --git a/tests/temporal.spec.ts b/tests/temporal.spec.ts new file mode 100644 index 0000000..2de8cb7 --- /dev/null +++ b/tests/temporal.spec.ts @@ -0,0 +1,47 @@ +/*****************************************************************************************************************/ + +// @author Michael Roberts +// @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) + }) +}) + +/*****************************************************************************************************************/