converter

package module
v2.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 5 Imported by: 0

README

kollavarsham

Circle CI Status Coverage Status GitHub Actions Status FOSSA Status

Convert Gregorian date to Kollavarsham date and vice versa

Install

TypeScript/JavaScript/Node.js NPM version
$ npm install kollavarsham
Python PyPI version
$ pip install kollavarsham
Go Go project version
go get github.com/kollavarsham/kollavarsham-go/converter
Java Maven version
<dependency>
  <groupId>org.kollavarsham.converter</groupId>
  <artifactId>kollavarsham-converter</artifactId>
  <version>2.0.1</version>
</dependency>
C#/dotnet NuGet version
$ dotnet add package KollavarshamOrg.Converter

Usage

Refer the samples repository for working examples.

TypeScript/JavaScript/Node.js
import { Kollavarsham } from 'kollavarsham';

const options = {
  system: 'SuryaSiddhanta',
  latitude: 10,
  longitude: 76.2
};

const kollavarsham = new Kollavarsham(options);

const today = kollavarsham.fromGregorianDate(new Date());

console.log(today.year, today.mlMasaName, today.date, `(${today.mlNaksatraName})`);
Python
import datetime
import pytz
import kollavarsham

now = pytz.utc.localize(datetime.datetime.utcnow())
kv = kollavarsham.Kollavarsham(latitude=10, longitude=76.2, system="SuryaSiddhanta")

today = kv.from_gregorian_date(date=now)
print(today.year, today.ml_masa_name, today.date, '(' + today.naksatra.ml_malayalam + ')')
Go
package main

import (
	"fmt"
	"time"

	"github.com/kollavarsham/kollavarsham-go/converter/v2"
)

func main() {

	latitude := float64(23.2)
	longitude := float64(75.8)
	system := "SuryaSiddhanta"
	kv := converter.NewKollavarsham(&converter.Settings{
		Latitude:  &latitude,
		Longitude: &longitude,
		System:    &system,
	})

	now := time.Now()
	today := kv.FromGregorianDate(&now)

	fmt.Printf("Today in Malayalam Year: %v %v %v (%v)\n", *today.Year(), *today.MlMasaName(), *today.Date(), *today.MlNaksatraName())
}
Java
package org.kollavarsham.tester;

import java.time.Instant;

import org.kollavarsham.converter.Kollavarsham;
import org.kollavarsham.converter.KollavarshamDate;
import org.kollavarsham.converter.Settings;
import org.kollavarsham.converter.Settings.Builder;

public class App {
    public static void main( final String[] args) {
        final Settings settings = new Builder().latitude(10).longitude(76.2).system("SuryaSiddhanta").build();
        final Kollavarsham kv = new Kollavarsham(settings);
        final KollavarshamDate today = kv.fromGregorianDate(Instant.now());
        System.out.println( today.getYear() + today.getMlMasaName() + today.getDate() + '(' + today.getMlNaksatraName() + ')' );
    }
}
C#/dotnet
using System;

namespace KollavarshamOrg.Tester
{
    class Program
    {
        static void Main(string[] args)
        {
            var settings = new Settings {
                Latitude = 10,
                Longitude = 76.2,
                System = "SuryaSiddhanta"
            };
            var kv = new Kollavarsham(settings);
            var today = kv.FromGregorianDate(DateTime.Now);
            Console.WriteLine($"{today.Year.ToString()} {today.MlMasaName} {today.Date.ToString()} ({today.MlNaksatraName})");
        }
    }
}

Documentation

TypeScript/JavaScript/Node.js

Check out the Kollavarsham class within the API documentation as this is the entry point into the library.

Release History

Check out the history at GitHub Releases

License

Copyright (c) 2014-2023 The Kollavarsham Team. Licensed under the MIT license.

FOSSA Status

Documentation

Overview

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Convert Gregorian date to Kollavarsham date and vice versa

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBaseDate_Override

func NewBaseDate_Override(b BaseDate, year *float64, month *float64, date *float64)

func NewJulianDate_Override

func NewJulianDate_Override(j JulianDate, year *float64, month *float64, day *float64)

func NewKollavarshamDate_Override

func NewKollavarshamDate_Override(k KollavarshamDate, year *float64, month *float64, day *float64)

func NewKollavarsham_Override

func NewKollavarsham_Override(k Kollavarsham, options *Settings)

func NewSakaDate_Override

func NewSakaDate_Override(s SakaDate, year *float64, month *float64, tithi *float64, paksa *string)

Types

type BaseDate

type BaseDate interface {
	// The `Ahargana` corresponding to this instance of the date. **Set separately after an instance is created**.
	//
	// In Sanskrit `ahoratra` means one full day and `gana` means count.
	// Hence, the Ahargana on any given day stands for the number of lunar days that have elapsed starting from an epoch.
	//
	// _Source_: http://cs.annauniv.edu/insight/Reading%20Materials/astro/sharptime/ahargana.htm
	Ahargana() *float64
	SetAhargana(val *float64)
	// The date corresponding to this instance of the date.
	Date() *float64
	SetDate(val *float64)
	// The gregorian date corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	GregorianDate() *time.Time
	SetGregorianDate(val *time.Time)
	// The `Julian Day` corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**
	// Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.
	//
	// _Source_: https://en.wikipedia.org/wiki/Julian_day
	JulianDay() *float64
	SetJulianDay(val *float64)
	// Returns the weekday (in Malayalam) for the current instance of date.
	MlWeekdayName() *string
	// The month corresponding to this instance of the date.
	Month() *float64
	SetMonth(val *float64)
	Naksatra() *Naksatra
	SetNaksatra(val *Naksatra)
	// The `Saura Divasa` (Solar Calendar Day) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraDivasa() *float64
	SetSauraDivasa(val *float64)
	// The `Saura Masa` (Solar Calendar Month) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraMasa() *float64
	SetSauraMasa(val *float64)
	// Returns the Saura Masa name for the current instance of date.
	SauraMasaName() *string
	// Returns the weekday (in English) for the current instance of date.
	WeekdayName() *string
	// The year corresponding to this instance of the date.
	Year() *float64
	SetYear(val *float64)
	// Converts the Date to a nicely formatted string with year, month and date.
	ToString() *string
}

Serves as the base class for both the {@link JulianDate} and {@link KollavarshamDate} classes.

**INTERNAL/PRIVATE**.

type JulianDate

type JulianDate interface {
	BaseDate
	// The `Ahargana` corresponding to this instance of the date. **Set separately after an instance is created**.
	//
	// In Sanskrit `ahoratra` means one full day and `gana` means count.
	// Hence, the Ahargana on any given day stands for the number of lunar days that have elapsed starting from an epoch.
	//
	// _Source_: http://cs.annauniv.edu/insight/Reading%20Materials/astro/sharptime/ahargana.htm
	Ahargana() *float64
	SetAhargana(val *float64)
	// The date corresponding to this instance of the date.
	Date() *float64
	SetDate(val *float64)
	// The gregorian date corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	GregorianDate() *time.Time
	SetGregorianDate(val *time.Time)
	// The `Julian Day` corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**
	// Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.
	//
	// _Source_: https://en.wikipedia.org/wiki/Julian_day
	JulianDay() *float64
	SetJulianDay(val *float64)
	// Returns the weekday (in Malayalam) for the current instance of date.
	MlWeekdayName() *string
	// The month corresponding to this instance of the date.
	Month() *float64
	SetMonth(val *float64)
	Naksatra() *Naksatra
	SetNaksatra(val *Naksatra)
	// The `Saura Divasa` (Solar Calendar Day) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraDivasa() *float64
	SetSauraDivasa(val *float64)
	// The `Saura Masa` (Solar Calendar Month) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraMasa() *float64
	SetSauraMasa(val *float64)
	// Returns the Saura Masa name for the current instance of date.
	SauraMasaName() *string
	// Returns the weekday (in English) for the current instance of date.
	WeekdayName() *string
	// The year corresponding to this instance of the date.
	Year() *float64
	SetYear(val *float64)
	// Converts the Date to a nicely formatted string with year, month and date.
	ToString() *string
}

Represents a Julian date's year, month and day `toGregorianDateFromSaka` method of the {@link Kollavarsham} class returns an instance of this type for dates older than `1st January 1583 AD`.

**INTERNAL/PRIVATE**.

func NewJulianDate

func NewJulianDate(year *float64, month *float64, day *float64) JulianDate

type Kollavarsham

type Kollavarsham interface {
	Settings() *Settings
	SetSettings(val *Settings)
	// Converts a Gregorian date to the equivalent Kollavarsham date, respecting the current configuration.
	//
	// Returns: Converted date.
	//
	// Example:
	//   const Kollavarsham = require('Kollavarsham');
	//   const kollavarsham = new Kollavarsham();
	//   let today = kollavarsham.fromGregorianDate(new Date(1979, 4, 22));
	//
	FromGregorianDate(date *time.Time) KollavarshamDate
	// Converts a Kollavarsham date (an instance of {@link kollavarshamDate}) to its equivalent Gregorian date, respecting the current configuration.
	//
	// This method Will return {@link JulianDate} object for any date before 1st January 1583 AD and
	// [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) objects for later dates.
	//
	// **This API has not been implemented yet**.
	//
	// Returns: Converted date.
	ToGregorianDate(date KollavarshamDate) *time.Time
	// Converts a Saka date (an instance of {@link sakaDate}) to its equivalent Gregorian date, respecting the current configuration.
	//
	// This method Will return {@link JulianDate} object for any date before 1st January 1583 AD and
	// [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) objects for later dates.
	//
	// Returns: Converted date.
	ToGregorianDateFromSaka(sakaDate SakaDate) KollavarshamDate
}

The Kollavarsham class implements all the public APIs of the library.

Create a new instance of this class, passing in the relevant options and call methods on the instance.

Example:

const Kollavarsham = require('kollavarsham');

const options = {
 system: 'SuryaSiddhanta',
 latitude: 10,
 longitude: 76.2
};

const kollavarsham = new Kollavarsham(options);

let todayInMalayalamEra = kollavarsham.fromGregorianDate(new Date());

let today = kollavarsham.toGregorianDate(todayInMalayalamEra);  // Not implemented yet

func NewKollavarsham

func NewKollavarsham(options *Settings) Kollavarsham

type KollavarshamDate

type KollavarshamDate interface {
	BaseDate
	// The `Ahargana` corresponding to this instance of the date. **Set separately after an instance is created**.
	//
	// In Sanskrit `ahoratra` means one full day and `gana` means count.
	// Hence, the Ahargana on any given day stands for the number of lunar days that have elapsed starting from an epoch.
	//
	// _Source_: http://cs.annauniv.edu/insight/Reading%20Materials/astro/sharptime/ahargana.htm
	Ahargana() *float64
	SetAhargana(val *float64)
	// The date corresponding to this instance of the date.
	Date() *float64
	SetDate(val *float64)
	// The gregorian date corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	GregorianDate() *time.Time
	SetGregorianDate(val *time.Time)
	// The `Julian Day` corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**
	// Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.
	//
	// _Source_: https://en.wikipedia.org/wiki/Julian_day
	JulianDay() *float64
	SetJulianDay(val *float64)
	// Returns the Kollavarsham month name (in English) for this instance of date.
	MasaName() *string
	// Returns the Kollavarsham month name (in Malayalam) for this instance of date.
	MlMasaName() *string
	// Returns the Kollavarsham Naksatra name (in Malayalam) for this instance of date.
	MlNaksatraName() *string
	// Returns the weekday (in Malayalam) for the current instance of date.
	MlWeekdayName() *string
	// The month corresponding to this instance of the date.
	Month() *float64
	SetMonth(val *float64)
	Naksatra() *Naksatra
	SetNaksatra(val *Naksatra)
	// Returns the Kollavarsham Naksatra name (in English) for this instance date.
	NaksatraName() *string
	SakaDate() SakaDate
	SetSakaDate(val SakaDate)
	// The `Saura Divasa` (Solar Calendar Day) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraDivasa() *float64
	SetSauraDivasa(val *float64)
	// The `Saura Masa` (Solar Calendar Month) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraMasa() *float64
	SetSauraMasa(val *float64)
	// Returns the Saura Masa name for the current instance of date.
	SauraMasaName() *string
	// Returns the weekday (in English) for the current instance of date.
	WeekdayName() *string
	// The year corresponding to this instance of the date.
	Year() *float64
	SetYear(val *float64)
	// Converts the Date to a nicely formatted string with year, month and date.
	ToString() *string
}

Represents a Kollavarsham date's year, month and date.

func NewKollavarshamDate

func NewKollavarshamDate(year *float64, month *float64, day *float64) KollavarshamDate

type MasaName

type MasaName struct {
	EnMalayalam *string `field:"required" json:"enMalayalam" yaml:"enMalayalam"`
	MlMalayalam *string `field:"required" json:"mlMalayalam" yaml:"mlMalayalam"`
	Saka        *string `field:"required" json:"saka" yaml:"saka"`
	Saura       *string `field:"required" json:"saura" yaml:"saura"`
}

func BaseDate_GetMasaName

func BaseDate_GetMasaName(masaNumber *float64) *MasaName

Returns the month names object that has Saka, Saura and Kollavarsham (English & Malayalam) month names for the specified index `masaNumber`.

func JulianDate_GetMasaName

func JulianDate_GetMasaName(masaNumber *float64) *MasaName

Returns the month names object that has Saka, Saura and Kollavarsham (English & Malayalam) month names for the specified index `masaNumber`.

func KollavarshamDate_GetMasaName

func KollavarshamDate_GetMasaName(masaNumber *float64) *MasaName

Returns the month names object that has Saka, Saura and Kollavarsham (English & Malayalam) month names for the specified index `masaNumber`.

func SakaDate_GetMasaName

func SakaDate_GetMasaName(masaNumber *float64) *MasaName

Returns the month names object that has Saka, Saura and Kollavarsham (English & Malayalam) month names for the specified index `masaNumber`.

type Naksatra

type Naksatra struct {
	EnMalayalam *string `field:"required" json:"enMalayalam" yaml:"enMalayalam"`
	MlMalayalam *string `field:"required" json:"mlMalayalam" yaml:"mlMalayalam"`
	Saka        *string `field:"required" json:"saka" yaml:"saka"`
}

type SakaDate

type SakaDate interface {
	BaseDate
	// The Adhimasa (`Adhika Masa`) prefix corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	Adhimasa() *string
	SetAdhimasa(val *string)
	// The `Ahargana` corresponding to this instance of the date. **Set separately after an instance is created**.
	//
	// In Sanskrit `ahoratra` means one full day and `gana` means count.
	// Hence, the Ahargana on any given day stands for the number of lunar days that have elapsed starting from an epoch.
	//
	// _Source_: http://cs.annauniv.edu/insight/Reading%20Materials/astro/sharptime/ahargana.htm
	Ahargana() *float64
	SetAhargana(val *float64)
	// The date corresponding to this instance of the date.
	Date() *float64
	SetDate(val *float64)
	// The fractional `Tithi`corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	FractionalTithi() *float64
	SetFractionalTithi(val *float64)
	// The gregorian date corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	GregorianDate() *time.Time
	SetGregorianDate(val *time.Time)
	// The `Julian Day` corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**
	// Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers.
	//
	// _Source_: https://en.wikipedia.org/wiki/Julian_day
	JulianDay() *float64
	SetJulianDay(val *float64)
	// The Kali year corresponding to this instance of the date.
	//
	// **Set separately after an instance is created**.
	KaliYear() *float64
	SetKaliYear(val *float64)
	// Returns the month name for this instance of SakaDate.
	MasaName() *string
	// Returns the weekday (in Malayalam) for the current instance of date.
	MlWeekdayName() *string
	// The month corresponding to this instance of the date.
	Month() *float64
	SetMonth(val *float64)
	Naksatra() *Naksatra
	SetNaksatra(val *Naksatra)
	// Returns the Saka Naksatra name for this instance of SakaDate.
	NaksatraName() *string
	// The original ahargana passed in to the celestial calculations (TODO: Not sure why we need this!?).
	OriginalAhargana() *float64
	SetOriginalAhargana(val *float64)
	// The Paksha/Paksa corresponding to this instance of the date.
	//
	// Paksha (or pakṣa: Sanskrit: पक्ष), refers to a fortnight or a lunar phase in a month of the Hindu lunar calendar.
	//
	// _Source_: https://en.wikipedia.org/wiki/Paksha
	Paksa() *string
	SetPaksa(val *string)
	// Returns the Saka year on this instance of SakaDate (same as the underlyiung `year` property from the {@link BaseDate} class).
	SakaYear() *float64
	// The `Saura Divasa` (Solar Calendar Day) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraDivasa() *float64
	SetSauraDivasa(val *float64)
	// The `Saura Masa` (Solar Calendar Month) for this instance of the date.
	//
	// **Set separately after an instance is created**.
	SauraMasa() *float64
	SetSauraMasa(val *float64)
	// Returns the Saura Masa name for the current instance of date.
	SauraMasaName() *string
	// The hour part from the sunrise time for this date.
	//
	// **Set separately after an instance is created**.
	SunriseHour() *float64
	SetSunriseHour(val *float64)
	// The minute part from the sunrise time for this date.
	//
	// **Set separately after an instance is created**.
	SunriseMinute() *float64
	SetSunriseMinute(val *float64)
	// Returns the Tithi on this instance of SakaDate (same as the underlyiung `date` property from the {@link BaseDate} class).
	//
	// In Vedic timekeeping, a tithi (also spelled thithi) is a lunar day, or the time it takes for the longitudinal angle between the Moon and the Sun to increase by 12°.
	// Tithis begin at varying times of day and vary in duration from approximately 19 to approximately 26 hours.
	//
	// _Source_: https://en.wikipedia.org/wiki/Tithi
	Tithi() *float64
	// Returns the Vikrama year corresponding to the Saka year of this instance.
	VikramaYear() *float64
	// Returns the weekday (in English) for the current instance of date.
	WeekdayName() *string
	// The year corresponding to this instance of the date.
	Year() *float64
	SetYear(val *float64)
	// Generates an instance of {@link KollavarshamDate} from this instance of SakaDate.
	GenerateKollavarshamDate() KollavarshamDate
	// Converts the Date to a nicely formatted string with year, month and date.
	ToString() *string
}

Represents an Saka date's year, month and paksa and tithi.

func NewSakaDate

func NewSakaDate(year *float64, month *float64, tithi *float64, paksa *string) SakaDate

type Settings

type Settings struct {
	Latitude  *float64 `field:"required" json:"latitude" yaml:"latitude"`
	Longitude *float64 `field:"required" json:"longitude" yaml:"longitude"`
	System    *string  `field:"required" json:"system" yaml:"system"`
}

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL