Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #96098

Re: What about my last date functions? there are some error?

From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.lang.c
Subject Re: What about my last date functions? there are some error?
Date 2016-11-08 16:20 +0000
Organization Fix this later
Message-ID <nvstum$jt5$1@dont-email.me> (permalink)
References <gh932ctlqkebuct208fqbbc7rdak1b2c1o@4ax.com> <87d1i69r5w.fsf@bsb.me.uk> <nvsd9k$nd4$1@dont-email.me> <871sym9dpv.fsf@bsb.me.uk>

Show all headers | View raw


On 08/11/16 15:46, Ben Bacarisse wrote:
> Richard Heathfield <rjh@cpax.org.uk> writes:

<snip>

>> long tojul(int yp,int mp,int dp){long
>> a=(14-mp)/12,y=yp+4800-a,m=mp+12*a-3,jdn=dp+(153*m+2)/5+365*y+y/4-y/100+y/400-32045;return
>> jdn;}
>> void fromjul(int*yp,int*mp,int*dp,long jdn){long
>> y=4716,j=1401,m=2,n=12,r=4,p=1461,v=3,u=5,s=153,w=2,b=274277,c=-38,f=jdn+j+(((4*jdn+b)/146097)*3)/4+c,e=r*f+v,g=(e%p)/r,h=u*g+w;*dp=(h%s)/u+1;*mp=((h/s+m)%n)+1;*yp=e/p-y+(n+m-*mp)/n;}
>
> I usually use the standard library function for this sort of thing, but
> if this works for you why rock the boat?

A search of N1570 for "Julian" yields no hits.

<time.h> gives us clock(), difftime(), mktime(), time(), timespec_get(), 
asctime(), ctime(), gmtime(), localtime(), and strftime(). None of these 
claims to work with Julian dates.

Of course, the standard library functions are perfectly adequate for 
many date-related tasks. But they do have their limitations, and for 
some purposes Julian dates are much more convenient. What's more, on 
some Unix systems the range of dates representable in a time_t is rather 
less than 140 years (roughly 1901 to 2038). If one needs to work with 
dates outside that range, one must find another way of doing so. The 
code I presented assumes astronomical numbering, i.e. there *is* a year 
0, and that may be a problem for some people, so I will make the lesser 
claim that it works from 1/1/1 AD to many millions of years into the 
future. (I tested various cases up to 1,000,000,000 years.)

>> But I never thought of a struct. So thanks for that.
>
> If you use the standard library functions there's even one ready to be
> used.

Yes, but it doesn't have a spare member for the Julian date.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What about my last date functions? there are some error? Rosario19 <Ros@invalid.invalid> - 2016-11-08 11:28 +0100
  Re: What about my last date functions? there are some error? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-08 10:55 +0000
    Re: What about my last date functions? there are some error? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-08 19:00 +0800
    Re: What about my last date functions? there are some error? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-08 11:04 +0000
      Re: What about my last date functions? there are some error? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-08 19:22 +0800
    Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 11:35 +0000
      Re: What about my last date functions? there are some error? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-08 15:46 +0000
        Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 16:20 +0000
          Re: What about my last date functions? there are some error? Rosario19 <Ros@invalid.invalid> - 2016-11-08 17:44 +0100
            Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 16:51 +0000
              Re: What about my last date functions? there are some error? Jerry Stuckle <jstucklex@attglobal.net> - 2016-11-08 13:21 -0500
          Re: What about my last date functions? there are some error? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-08 18:06 +0000
            Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 18:56 +0000
              Re: What about my last date functions? there are some error? Keith Thompson <kst-u@mib.org> - 2016-11-08 12:05 -0800
              Re: What about my last date functions? there are some error? David Brown <david.brown@hesbynett.no> - 2016-11-08 21:10 +0100
                Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 20:16 +0000
          Re: What about my last date functions? there are some error? jadill33@gmail.com - 2016-11-08 11:16 -0800
            Re: What about my last date functions? there are some error? Richard Heathfield <rjh@cpax.org.uk> - 2016-11-08 20:08 +0000
            Re: What about my last date functions? there are some error? Keith Thompson <kst-u@mib.org> - 2016-11-08 12:11 -0800
              Re: What about my last date functions? there are some error? Keith Thompson <kst-u@mib.org> - 2016-11-08 12:29 -0800
      Re: What about my last date functions? there are some error? Rosario19 <Ros@invalid.invalid> - 2016-11-08 17:41 +0100
        Re: What about my last date functions? there are some error? asetofsymbols@gmail.com - 2016-11-08 11:26 -0800
          Re: What about my last date functions? there are some error? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-08 19:38 +0000
  Re: What about my last date functions? there are some error? Keith Thompson <kst-u@mib.org> - 2016-11-08 08:19 -0800

csiph-web