coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date function enhancement Request LibreOffice doc attached.


From: Pádraig Brady
Subject: Re: Date function enhancement Request LibreOffice doc attached.
Date: Thu, 18 Jan 2018 18:43:48 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 17/01/18 08:16, Leslie S Satenstein wrote:
> I noted that there is no "date +%letter" that will tell me directly, the 
> number of days since  January 1, 1970.  or  julian date routines
> 
> 
> v=date +%secho (( $v / 86400 ))
> 17548  #the number of days since 1 jan 1970 ( a Thursday)
> 
> It would be preferable if the julian date rouitine shown below was used. It 
> allows modulo 7 arithmetic to determine the day of the week. With the code 
> shown incorporated as two +%? values (forward to julian and back). benefit  
> easy calculation of the difference between two dates as well, the day of the 
> week.  With the logic shown,     year 0000 12 31 is a Sunday.   
> 
> C code for julian to gregorian and reverse is provided below my signature.  
> The code was provided in the defunct Dr Dobbs journal by Dr. Peter Meyers 
> (his paper is attached) and is in the publc domain.
>  Some test results with the attached algorithms. 
> juldate  1970 1 1 
> Julian Day = 2440588 WeekDay=4, WeekdayISO=4="Thursday" 
> Year=1970,Month=01,Day=01    (matches cal 1970 )
> juldate  2018 1 17
> Julian Day = 2458136 WeekDay=3, WeekdayISO=3="Wednesday" 
> Year=2018,Month=01,Day=17  (modulo 7 on Julian day = 3)
> Does coreutils have anything similar, so that the date function can be left 
> alone?
> 
> Regards 
>  Leslie
>  Leslie Satenstein
> Montréal Québec, Canada
> 
> 
> The Julian day (jd) is computed from Gregorian day, month and year(d, m, y) 
> as follows: 
>  jd = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +
>       ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 -
>       ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 +
>       d - 32075
> Division is to be understood as in integer arithmetic, with theremainders 
> discarded. 
> 
> Converting from the Julian day to the Gregorian day is performedthus: 
>     l = jd + 68569
>     n = ( 4 * l ) / 146097
>     l = l - ( 146097 * n + 3 ) / 4
>     i = ( 4000 * ( l + 1 ) ) / 1461001 //(that's 1,461,001)
>     l = l - ( 1461 * i ) / 4 + 31
>     j = ( 80 * l ) / 2447
>     d = l - ( 2447 * j ) / 80
>     l = j / 11
>     m = j + 2 - ( 12 * l )
>     y = 100 * ( n - 49 ) + i + l       //(that's a lower-case L)

Yes maybe. The same considerations apply as to the %q (quarter) extension
that was discussed at:
https://lists.gnu.org/archive/html/coreutils/2016-10/msg00002.html
Are there any other formatters that return this info?

thanks,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]