<commit_before>/*
  Copyright 1993, 1994, 1998 University of Rhode Island
 
  Permission to use, copy, modify and distribute this software and its
  documentation for any purpose is hereby granted without fee, provided that
  the above copyright notice appear in all copies and that both that
  copyright notice and this permission notice appear in supporting
  documentation, and that the name of U.R.I. not be used in advertising or
  publicity pertaining to distribution of the software without specific,
  written prior permission.  U.R.I. makes no representations about the
  suitability of this software for any purpose.  It is provided "as is"
  without express or implied warranty.
 
  U.R.I. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.R.I.
  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN 
  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

// These functions handle date translation between Julian and Gregorian
// formats. 8/12/93 jhrg
//
// This code was originally copied from one of the ACM's code libraries and
// use in the browsed image server. That version was written in C. 

// $Log: date_proc.cc,v $
// Revision 1.1  1998/09/17 17:46:40  jimg
// Created
//

#include <assert.h>

#include "config_dap.h"

static char __unused__ rcsid[]={"$Id: date_proc.cc,v 1.1 1998/09/17 17:46:40 jimg Exp $"};

// You have to add one to days[1] if the year is a leap year. Since the month
// number in a Gregorian date is ones-based, fill element zero below to
// avaoid gratuitous subtractions of the index value. Note that the fill
// value is never used. 9/4/98 jhrg
static int days_arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

static inline int
is_leap(int year) 
{
    return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}

static inline int
days(int year, int month)
{
#if 0
    assert(year > 0);
    assert(month > 0 && month < 13);
#endif

    if (month == 2 && is_leap(year))
	return 29;
    else
	return days_arr[month];
}

/**
  Given a gregorian date in the years, month and day, return the Julian day
  number. 
  
  NB: I am not sure this code deals correctly with dates before 1100 A.D.

  @param year The year. Must be A.D. and `fully qualified'
  @param month The month. Ones-based month number (Jan = 1, Dec = 12).
  @param day The day. Ones-based day number.
  @see ACM Collected algorithms.
  @return Julian day number. 
*/

long 
julian_day(int year, int month, int day)
{
    assert(year > 0);
    assert(month > 0 && month < 13);
    assert(day > 0 && day <= days(year, month));

    long jdn;

    jdn = (long) year * 367 + month * 275 / 9
	- (year + (month > 2)) * 7 / 4
	    - ((year - (month < 3)) / 100 + 1) * 3 / 4 + day + 1721029L;

    return (jdn);
}

/**
  Given a Julian day number, return the Gregorian date. The Julian day number
  is passed as a double while the gregorian date is returned using six
  `value-result' parameters:

  @see Algorithm 199 in Collected algorithms of the CACM Author: <NAME>, Translator: <NAME><commit_msg>Cleaned up the doc++ comments.<commit_after>/*
  Copyright 1993, 1994, 1998 University of Rhode Island
 
  Permission to use, copy, modify and distribute this software and its
  documentation for any purpose is hereby granted without fee, provided that
  the above copyright notice appear in all copies and that both that
  copyright notice and this permission notice appear in supporting
  documentation, and that the name of U.R.I. not be used in advertising or
  publicity pertaining to distribution of the software without specific,
  written prior permission.  U.R.I. makes no representations about the
  suitability of this software for any purpose.  It is provided "as is"
  without express or implied warranty.
 
  U.R.I. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.R.I.
  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN 
  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

// These functions handle date translation between Julian and Gregorian
// formats. 8/12/93 jhrg
//
// This code was originally copied from one of the ACM's code libraries and
// use in the browsed image server. That version was written in C. 

// $Log: date_proc.cc,v $
// Revision 1.2  1998/11/10 17:47:43  jimg
// Cleaned up the doc++ comments.
//
// Revision 1.1  1998/09/17 17:46:40  jimg
// Created
//

#include <assert.h>

#include "config_dap.h"

static char __unused__ rcsid[]={"$Id: date_proc.cc,v 1.2 1998/11/10 17:47:43 jimg Exp $"};

// You have to add one to days[1] if the year is a leap year. Since the month
// number in a Gregorian date is ones-based, fill element zero below to
// avoid gratuitous subtractions of the index value. Note that the fill
// value is never used. 9/4/98 jhrg
static int days_arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

static inline int
is_leap(int year) 
{
    return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}

static inline int
days(int year, int month)
{
#if 0
    assert(year > 0);
    assert(month > 0 && month < 13);
#endif

    if (month == 2 && is_leap(year))
	return 29;
    else
	return days_arr[month];
}

/**
  Given a gregorian date in year, month and day, return the Julian day
  number.
  
  NB: I am not sure this code deals correctly with dates before 1100 A.D.

  @param year The year. Must be A.D. and `fully qualified'
  @param month The month. Ones-based month number (Jan = 1, Dec = 12).
  @param day The day. Ones-based day number.
  @see ACM Collected algorithms.
  @return The Julian day number. */

long 
julian_day(int year, int month, int day)
{
    assert(year > 0);
    assert(month > 0 && month < 13);
    assert(day > 0 && day <= days(year, month));

    long jdn;

    jdn = (long) year * 367 + month * 275 / 9
	- (year + (month > 2)) * 7 / 4
	    - ((year - (month < 3)) / 100 + 1) * 3 / 4 + day + 1721029L;

    return (jdn);
}

/**
  Given a Julian day number, return the Gregorian date. The Julian day number
  is passed as a double while the gregorian date is returned using six
  `value-result' parameters:

  @see Algorithm 199 in Collected algorithms of the CACM Author: <NAME>, Translator: <NAME>
{'fraction_non_alphanumeric': 0.09251232999551637, 'fraction_numerical': 0.04364071140337767, 'mean_word_length': 3.222082018927445, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7605695', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2026, 'n_words': 969}