Ruby – Find Astronomical Julian Day – ajd Method with Examples

ajd method is used to return the astronomical Julian day number. This method produced the fractional number, which is not properly adjusted by the offset. ajd is a part of Date Library in Ruby.

Syntax of ajd Method in Ruby

The syntax of ajd method in Ruby Language is:

DateTime.new(x).ajd

 

Parameters of ajd Method in Ruby

x – Where x is any date which is required to be converted into an Astronomical Julian day number. This parameter is required.

 

Error Handling

If the x parameter is not a valid calander date the ajd method returns an error. ajd method generates a new julian day number by indicating from a calander date given in a code.

 

Return Value of ajd method in Ruby

ajd method will return Astronomical Julian Day number from a valid date given in a code.

 

Use of ajd method / function in Ruby

# import date library
require 'date'
x = DateTime.new(2016,2,3).ajd
puts x

Output:
4914843/2

Convert Date into Astronomical Julian Day Number in Ruby

# import date library
require 'date'
x = DateTime.new(2016,2,10).ajd
puts x

Output:
4914857/2

ajd method / function explained

# import date library
require 'date'
x = DateTime.new(2015,7,17).ajd
puts x

Output:
4914441/2