# Jesus 'n Jim

A mainly PC (some Mac) site w/Software, Computer Repair Info, How-To's on Using Computers
Technical Support 1-360-521-2060 (my business line cell)

## Overview

Both scripts are required to make a deadline.

this is also a fun page for kids - most kids would like the fun of seeing exactly how old they are to the DOT!

## Date Difference from NOW

year(+/-):
month(1..12):
day(1..31):
hour(0..23):
minute(0..59):
second(0..59):
millisecond(0..999):

Result: years, months days or total days ::.

## Date Difference

1:year(+/-):
1:month(1..12):
1:day(1..31):
1:hour(0..23):
1:minute(0..59):
1:second(0..59):
1:millisecond(0..999):

2:year(+/-):
2:month(1..12):
2:day(1..31):
2:hour(0..23):
2:minute(0..59):
2:second(0..59):
2:millisecond(0..999):

Result: years, months days or total days ::.

julian-gregorian.js - javascript source

## function specifications

```//gregorian-julian calendar conversion routines.  do not use with
//gregorian dates under 1500AD.  cerain events occurred which interrupted
//the calendar.
//algorithm from http://en.wikipedia.org/wiki/Julian_day

/*
Author: Jim Michaels
Abstract: function library for conversion and time extraction from Julian and
Gregorian Dates and Javascript Date() objects.
Create Date:  , 2008
Current Date: Oct 24, 2009
Version 2.2

If you want to do Gregorian date differences based on Julian date differences,
make sure you add GregorianToJulian(0,1,1,12,0,0,0) to the result. e.g.
var dt1=GregoriantoJulian(y1,m1,d1,h1,mi1,s1,ms1);
var dt2=GregoriantoJulian(y2,m2,d2,h2,mi2,s2,ms2);
var diff=dt1-dt2+GregorianToJulian(0,1,1,12,0,0,0);
everything else is normal.

This program is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .

*/
```

These functions include a timestamp format I named DTIME, which is a simple integer based on JDN (Julian Day Number and for the time instead of using JD time in a floating point where you can possibly get error, I chose

javascript is good for integers up to 253 bits before it starts converting them to floating point. there is no problem with using this format except that there are no leap seconds.

this means that javascript is capable of handling 2^53/(1000*60*60*24*366)=285,420.92094 years. if you want to see that on MATHML, it's $\frac{{2}^{53}\text{JS integer size}}{1000×60×60×24×365.25}=285,420.92094\text{years.}$ no problem for now. :-)

DTime is calculated as dtime=(JDN*1000*60*60*24) + (hours*1000*60*60) + (minutes*1000*60)+ (seconds*1000) + milliseconds;

Gregorian Epoch is actually `GregorianToDTime(1,1,1,0,0,0,0);` but because I am doing differences, I have to use `GregorianToDTime(0,1,1,0,0,0,0);`

## function list

`function GregorianToJulian(Y,Mo,D,H,Mi,S,ms)`
returns Julian date number.
Y=year -4800..whenever+
Mo=month 1..12
D=day 1..31
H=hour 0..23
Mi=minute 0..59
S=second 0..59
ms=millisecond 0..999

`function JulianFromDate(date)` returns julian date given a js Date() object.

`function DateToJulian(date)` returns julian date given a js Date() object.

`function DTimeFromDate(date)` returns DTime timestamp given a js Date() object.

`function DateToDTime(date)` returns DTime timestamp given a js Date() object.

## to DTime/Julian functions

`function GregorianToJulian(Y,Mo,D,H,Mi,S,ms)` returns julian date given individual Gregorian date and time numbers.

`function GregorianToDTime(Y,Mo,D,H,Mi,S,ms)` returns DTime timestamp given individual Gregorian date and time numbers.

`function JulianToDate(JulianDate)` returns js Date() object given Julian date

`function DateFromJulian(JulianDate)` returns js Date() object given Julian date

`function DTimeToDate(dtime)` returns js Date() object given DTime timestamp

`function DateFromDTime(dtime)` returns js Date() object given DTime timestamp

## to Gregorian functions

`function JulianToGregorianY(JulianDate)` returns Gregorian Year given Julian date

`function JulianToGregorianMo(JulianDate)` returns Gregorian Month given Julian date

`function JulianToGregorianD(JulianDate)` returns Gregorian Day given Julian date

`function JulianToGregorianH(JulianDate)` returns Gregorian Hour given Julian date

`function JulianToGregorianMi(JulianDate)` returns Gregorian Minutes given Julian date

`function JulianToGregorianS(JulianDate)` returns Gregorian Seconds given Julian date

`function JulianToGregorianMs(JulianDate)` returns Gregorian Milliseconds given Julian date

`function JulianToGregorianFracSec(JulianDate)` returns Gregorian Seconds (fractional) given Julian date

`function DTimeToGregorianY(dtime)` returns Gregorian Year given DTime timestamp

`function DTimeToGregorianMo(dtime)` returns Gregorian Month given DTime timestamp

`function DTimeToGregorianD(dtime)` returns Gregorian Day given DTime timestamp

`function DTimeToGregorianH(dtime)` returns Gregorian Hour given DTime timestamp

`function DTimeToGregorianMi(dtime)` returns Gregorian Minutes given DTime timestamp

`function DTimeToGregorianS(dtime)` returns Gregorian Seconds given DTime timestamp

`function DTimeToGregorianMs(dtime)` returns Gregorian Milliseconds given DTime timestamp

`function DTimeToGregorianFracSec(dtime)` returns Gregorian Seconds (fractional) given DTime timestamp

## auxilliary functions

`function GregorianDiffWithoutEpoch(yr1,mo1,dy1,hr1,mi1,sec1,ms1, yr2,mo2,dy2,hr2,mi2,sec2,ms2)`

`function GregorianDiffWithEpoch(yr1,mo1,dy1,hr1,mi1,sec1,ms1, yr2,mo2,dy2,hr2,mi2,sec2,ms2)`

`function to2DigitString(n)` to2DigitString(n) converts integer n to a string with a leading zero and returns the string. It is useful for making time strings.

`function zeropad(n,numdigits)` prepends numdigits zeros to the number n after converting it to a string and returns the resulting string.

`function fmod(a,b)`
returns a%b;
as required by julian date caldculations. % in js apparently also works with floats.

`function fdiv(a,b)` integer a/b. returns floor(floor(a)/floor(b)); as required by julian date calculations. equivelant to integer division in C.