LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-14-2013, 02:09 PM   #16
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,056

Rep: Reputation: Disabled

@Mark Pettit:

“Competence, like truth, beauty and contact lenses, is in the eye of the beholder.”

Laurence J. Peter, The Peter Principle (1969)

This applies as well to decency (of a programing language), I guess...
 
1 members found this post helpful.
Old 03-14-2013, 02:11 PM   #17
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
My script is for more practical use:

from-to
Code:
#!/bin/bash

if [ "$1" == "" ]
then
    echo "from-to from_date [to_date] [-v | --verbose]"
    echo
    echo "date_format: YYYY-MM-DD"
    echo
    exit
fi

TODAY=`date +"%Y-%m-%d"`

fromdate=$1

if [ "`echo $2 | grep '[0-9]'`" != "" ]
then
    todate=$2
else
    todate=$TODAY
fi

from=`echo $fromdate | awk  -F\- '{print $1$2$3}'`
START_DATE=`date --date=$from +"%s"`

to=`echo $todate | awk  -F\- '{print $1$2$3}'`
END_DATE=`date --date=$to +"%s"`

DAYS=$((($END_DATE - $START_DATE) / 86400 ))

if [ "`echo $* | grep '\-v'`" != "" ]
then
    echo -n "$fromdate $todate "
fi
echo $DAYS
Here’s the number of the days between Slackware 13.37 and 14.0 releases:

from-to 2011-04-25 2012-09-26
Code:
520
Here’s the number of the days between Slackware 14.0 release and today:

from-to 2012-09-26
Code:
169

Last edited by w1k0; 03-14-2013 at 03:01 PM. Reason: update
 
Old 03-14-2013, 02:30 PM   #18
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by stf92 View Post
Yes, the satisfaction one gets when one sees the program working is unrivaled. The first job they gave me when I began working at a certain software firm was to write a program to compute number of days between dates. It was the epoch of minicomputers, PDP-11 for instance.

I chose 1784 not to go before 1600, because I was not sure about the year the Gregorian reform began and did not want to give a pre-Gregorian date as an example. I guess the bug is in the date command?
not in the date command....the week after but before New Year's Day, it's spits out negative integers.
 
Old 03-14-2013, 02:32 PM   #19
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by T3slider View Post
I don't believe it is a bug -- it is a rounding error. If you explicitly pass two dates then you will get the correct difference since it will assume 00:00, whereas if you just get the difference from the current time it might be half a day or more off, which would round improperly. I think though that bash rounds by cutting off the decimal point so it isn't the most accurate.
Code:
echo "($(date +%s)-($(date -d "April 7 1784" +%s)))/86400" | bc -l
would give you an unrounded value from the current day/time, though
Code:
echo "($(date -d "March 14" +%s)-($(date -d "April 7 1784" +%s)))/86400" | bc -l
is probably still better.
If the current day could be rounded (by truncation) before the subtraction then the result would be accurate (the exact or true difference in days).
 
Old 03-14-2013, 02:32 PM   #20
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Here, just for fun, is ndays.

Save below as ndays.c, compile it with
Code:
cc -o ndays ndays.c -lm
Use it as
Code:
ndays
Enter Lower Date (MM/DD/YYYY): 04/07/1784
Enter Upper Date (MM/DD/YYYY): 03/14/2013
Number of Days: 83616
This uses Julian Day Numbers; i.e., add one per day (Julian Day Numbers start at Julian Day 0: 01/01/-4713 -- that's a long, long time ago); today is Julian Day Number 24,56,366.

Here's the source (do what you wish with it):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

static	time_t	julday	(int, int, int);

void	main	(void)
{
	int	ldd, lmm, lyy;
	int	udd, umm, uyy;

	(void) fprintf (stdout, "Enter Lower Date (MM/DD/YYYY): ");
	(void) scanf ("%d/%d/%d", &lmm, &ldd, &lyy);
	(void) fprintf (stdout, "Enter Upper Date (MM/DD/YYYY): ");
	(void) scanf ("%d/%d/%d", &umm, &udd, &uyy);
	(void) fprintf (stdout, "Number of Days: %ld\n",
	    julday (umm, udd, uyy) - julday (lmm, ldd, lyy));
}

/*	Gregorian Calendar adopted 15 Oct 1582		*/
#define	IGREG	(15+31L*(10+12L*1582))

static	time_t	julday	(int mm, int id, int iyyy)
{
	time_t	jul;
	int	ja, jy, jm;

	if (iyyy == 0) {
		(void) fprintf (stderr, "julday:\tthere is no year zero\n");
		exit (1);
	}
	if (iyyy < 0)
		++iyyy;
	if (mm > 2) {
		jy = iyyy;
		jm = mm + 1;
	} else {
		jy = iyyy - 1;
		jm = mm + 13;
	}
	jul = (time_t) (floor (365.25 * jy) +
	    floor (30.6001 * jm) + id + 1720995);
	if (id + 31L * (mm + 12L * iyyy) >= IGREG) {
		ja = 0.01 * jy;
		jul += 2 - ja + (int) (0.25 * ja);
	}
	return (jul);
}

#undef	IGREG
Have a little fun.
 
3 members found this post helpful.
Old 03-14-2013, 02:38 PM   #21
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by saulgoode View Post
For Britain (and the U.S.), the switch took place in September of 1752. The 'cal' command gets this right:
Code:
$ cal 9 1752
   September 1752   
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
The 'date' command doesn't seem to account for this:
Code:
$ echo $(($(date --date="1752-9-14" +%s)/-86400)) days ago
79365 days ago
$ echo $(($(date --date="1752-9-2" +%s)/-86400)) days ago
79377 days ago
You're right!
 
Old 03-14-2013, 02:46 PM   #22
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
Great program, troyaine!
 
Old 03-14-2013, 02:50 PM   #23
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by Didier Spaier View Post
Still waiting for solution working since year 1 (Julian then Gregorian calendars).

I've done that as an exercise in Cobol long ago (circa 1977, IIRC :-)

Batch processing of Hollerith punched cards, I was allowed to test only once a day :^)
I instead had to pay for the cards getting punched and for computer time. I had a program that was correct but would have completed execution by about year 10**40. But I left the computer facilities thinking the program had some error and having spent good money by the way.
 
Old 03-14-2013, 02:54 PM   #24
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 15.0
Posts: 619

Rep: Reputation: 299Reputation: 299Reputation: 299
Hi @Didier : Well, beauty may be in the eye of the beholder, but I think we all agree that the Mona Lisa is a beautiful painting, and that Leonard Cohen's Hallelujah is beautiful music .... My history is 33 years of programming, from Fortran, Pascal, Basic, Assembler (Various), Cobol (the worst), "c", "c++", "sql", and then some smatterings of other languages which I've had the misfortune to look into, like Perl and Java. But I've worked professionally for the last 10 years in Python, and my life is better for it. Sometimes I have so much fun and pleasure writing in this language that I feel guilty pulling a pay-cheque at the end of the month :-)
 
Old 03-14-2013, 02:55 PM   #25
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Keep in mind that a lot of the adoption of the Gregorian calendar depended upon religion -- Britain didn't mandate the change until 1752 (when the US was still a British colony). When you're calculating this stuff, you really need to know "where" you're calculating for; there's a nice chart of Gregorian adoption dates at http://en.wikipedia.org/wiki/Gregorian_calendar if you want to be picky.

If you're trying to figure out Gregorian dates for old records (prior to adoption)...

Hope this helps some.
 
Old 03-14-2013, 03:01 PM   #26
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by rg3 View Post
Before the BSD ncal command accepted a flag allowing you to select the Gregorian reform date, I wrote a small Python script to print calendars assuming October 1582. Much of that code can be used to calculate the difference.

https://github.com/rg3/cal_1582

Also, the source of the ncal BSD command is interesting as it has an algorithm to count days too and calculate the day of the week for any date. It's pretty simple, actually.

http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/ncal/
Texas Instruments put one in their TI-59. It did not use tables but a certain intersting algorithm.
 
Old 03-14-2013, 03:14 PM   #27
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,056

Rep: Reputation: Disabled
Quote:
Originally Posted by Mark Pettit View Post
I think we all agree that the Mona Lisa is a beautiful painting
I do. I have he chance to live 35 min by feet from the Musée du Louvre. BTW there is another woman's portrait from Léonard that I saw at the National Gallery of Art in Washington back in 1987. I believe this is the only painting by Vinci permanently exposed in the USA.
Quote:
Originally Posted by Mark Pettit View Post
and that Leonard Cohen's Hallelujah is beautiful music
hem, well... Maybe I do not consider myself as included in all, then

Last edited by Didier Spaier; 03-14-2013 at 03:19 PM.
 
Old 03-14-2013, 04:21 PM   #28
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
Here’s the file including Slackware releases dates (the data got from Wikipedia):

slackware-releases
Code:
1.0 July 17, 1993
1.1.0 November 5, 1993
1.1.2 February 5, 1994
2.0 July 2, 1994
2.1 October 31, 1994
2.2 March 30, 1995
2.3 May 24, 1995
3.0 November 30, 1995
3.1 June 3, 1996
3.2 February 17, 1997
3.3 June 11, 1997
3.4 October 14, 1997
3.5 June 9, 1998
3.6 October 28, 1998
3.9 May 10, 1999
4.0 May 17, 1999
7.0 October 25, 1999
7.1 June 22, 2000
8.0 July 1, 2001
8.1 June 18, 2002
9.0 March 19, 2003
9.1 September 26, 2003
10.0 June 23, 2004
10.1 February 2, 2005
10.2 September 14, 2005
11.0 October 2, 2006
12.0 July 1, 2007
12.1 May 2, 2008
12.2 December 10, 2008
13.0 August 26, 2009
13.1 May 24, 2010
13.37 April 27, 2011
14.0 September 28, 2012
Here’s the script that processes the above file using from-to script from the post #17:

slacky
Code:
#!/bin/bash

if [ "$1" == "" ] ; then echo "$0 file" ; exit ; fi

> $1.new
grep -n '' $1 | sed 's/:/ /;s/ /_/g' | \
while read line junk
do
    line=`echo $line | sed 's/_/ /g'`
    number=`echo $line | awk '{print $1}'`
    version=`echo $line | awk '{print $2}'`
    date=`echo $line | awk '{print $3,$4,$5}'`
    date=`date --date="$date" +"%Y-%m-%d"`
    echo $number:$version:$date >> $1.new
done

cat $1.new | \
while read line junk
do
    line=`echo $line | sed 's/:/ /g'`
    number=`echo $line | awk '{print $1}'`
    version[$number]=`echo $line | awk '{print $2}'`
    date[$number]=`echo $line | awk '{print $3}'`
    if [ $number -ge 2 ]
    then
        prev_number=`expr $number - 1`
        period=`from-to ${date[$prev_number]} ${date[$number]}`
        echo "${version[$prev_number]} -> ${version[$number]} = $period"
    fi
done
This is the output of the above script:

slacky slackware-releases
Code:
1.0 -> 1.1.0 = 111
1.1.0 -> 1.1.2 = 92
1.1.2 -> 2.0 = 146
2.0 -> 2.1 = 121
2.1 -> 2.2 = 149
2.2 -> 2.3 = 55
2.3 -> 3.0 = 190
3.0 -> 3.1 = 185
3.1 -> 3.2 = 259
3.2 -> 3.3 = 113
3.3 -> 3.4 = 125
3.4 -> 3.5 = 238
3.5 -> 3.6 = 141
3.6 -> 3.9 = 193
3.9 -> 4.0 = 7
4.0 -> 7.0 = 161
7.0 -> 7.1 = 241
7.1 -> 8.0 = 374
8.0 -> 8.1 = 352
8.1 -> 9.0 = 274
9.0 -> 9.1 = 190
9.1 -> 10.0 = 271
10.0 -> 10.1 = 224
10.1 -> 10.2 = 223
10.2 -> 11.0 = 383
11.0 -> 12.0 = 272
12.0 -> 12.1 = 306
12.1 -> 12.2 = 222
12.2 -> 13.0 = 258
13.0 -> 13.1 = 271
13.1 -> 13.37 = 338
13.37 -> 14.0 = 520

Last edited by w1k0; 03-14-2013 at 05:47 PM. Reason: debug (takes into consideration 1.0 -> 1.1.0 period)
 
Old 03-14-2013, 04:33 PM   #29
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,056

Rep: Reputation: Disabled
Some of us will be tempted to forecast next Slackware release's date from the average delay between two releases, I guess

The same people would have expected Slackware 14.0 a little sooner, though.

Last edited by Didier Spaier; 03-14-2013 at 05:21 PM.
 
Old 03-14-2013, 05:32 PM   #30
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Didier Spaier View Post
Some of us will be tempted to forecast next Slackware release's date from the average delay between two releases, I guess
That’s rather natural idea in such a case. To “predict” the date one can use different methods. The more methods she’ll try the more results she’ll gain. As a result one of these “predictions” will be really close to the actual date of the next release. That’s the whole truth about the predictions and the numerology.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Manipulate Date based on number of days? pinga123 Solaris / OpenSolaris 1 03-02-2012 02:05 PM
no of days between two dates in yyyymmdd format csegau Programming 1 09-18-2011 02:15 PM
[SOLVED] looping thru input files with different number of days. btacuso Programming 8 11-03-2010 11:54 PM
[SOLVED] How to subtract two dates in a file to get number of days? btacuso Linux - Newbie 2 07-13-2010 11:33 AM
How the complier compute the number after the kernel symbol? lawrencelee Linux - Software 3 01-14-2003 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 04:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration