Looking for date algorithms

unix

    Next

  • 1. Problem implementing sockets with C++ [long]
    > [C++ debris] >> void Server::accept ( Server& sock ) >> { >> if ( !(Socket::accept ( sock ))) >> { >> std::cout<<"Could not accept socket."; >> } >> else >> { >> char bufchars[MAXRECV+1]; >> while (this->receiveString(bufchars)) >> { > This needs to be s.receiveString, because you need to use the > socket created by accept for receiving, not the listening socket. > Apart from that, after reconstructing your headers from the ones > posted as part of the magazine article and fixing a few bugs in your > code (eg #include <cstdlib>) this works for me without segfaulting. > Code for that: Thanks a lot!! Can you paste the code as text or send the zip file as an attachment to my email (H.L at softhome dot net)? My web based usenet reader doesn't seem to be able to oepen attached files. Han -- Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet Die Signatur lt sich nach Belieben anpassen ;-)
  • 2. mblk
    Hi, Can someone please explain how network packets are mapped to mblks. I have googled quite a bit, but nothing concrete comes up. Any links would also be great! Thank you, Vis
  • 3. Creating Posix message queue with attribute get error (invalid argument)
    Why not Following code always get "Invalid argument" error? $ ./a.out /tmp.333 Wrong! : Invalid argument #include <mqueue.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include <iostream> using namespace std; #define FILE_MODE S_IRUSR|S_IWUSR struct mq_attr attr; int main(int argc, char** argv){ int c, flags; mqd_t mqd; flags = O_RDWR|O_CREAT; if( argc != 2){ printf("usage: mqcreate <name>\n"); return -1; } attr.mq_maxmsg = 512; attr.mq_msgsize = 512; mqd = mq_open( argv[argc -1 ], flags, FILE_MODE, &attr); if(mqd < 0){ perror("Wrong!\n"); return -1; } mq_close(mqd); exit(0); }
  • 4. Subtracting Microseconds from Timestamp
    Hello, I'm a UNIX newbie. I'm trying to get the time elapse between some queries. I have a timestamp, and then another time in miliseconds. I'm having trouble getting the difference. For example, initial time is 1251935975 but the microseconds I'm given after the query is 80192300. Thanks in advanced for your explanations and civility.
  • 5. Got "permission denied" when creating a posix message queue.
    Below code is the excise from Unix network programming: IPC. But after building the code using : g++ thisfile.cpp -lrt running: a.out /tmp/mq.1234 will cause the code print "errno=13 Permission denied". How to solve this issue? Thank you! #include <mqueue.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #define FILE_MODE S_IRUSR|S_IWUSR int main(int argc, char** argv){ int c, flags; mqd_t mqd; flags = O_RDWR|O_CREAT; while( ( c = getopt(argc, argv, "e" ) ) != -1 ){ switch (c){ case 'e': flags |= O_EXCL; break; } } if( optind != argc - 1 ){ printf("usage: mqcreate [ -e ] <name>"); return -1; } printf("FILE_MOED=%d\n", FILE_MODE); mqd = mq_open( argv[optind], flags, FILE_MODE, NULL); printf("The message queue d: %d \n", mqd); printf("%d :%s \n", errno, strerror(errno)); mq_close(mqd); exit(0); }

Looking for date algorithms

Postby Ramon F Herrera » Fri, 04 Sep 2009 15:52:06 GMT

One of my CS professors always insisted: "Do not reinvent the wheel -
If something works, just COPY it".

With that in mind, where can I find an algorithm/snippet that
converts:

 date --> week number

and its inverse:

 week number --> date range

Just to make sure:

The year has 52 weeks, and their week numbers are: week 1, week 2,
week 3, etc.

I believe that today (9/3/2009) we are in week number 36 of the year.

TIA,

-Ramon

 http://www.**--****.com/ 


Re: Looking for date algorithms

Postby Valentin Nechayev » Fri, 04 Sep 2009 16:03:21 GMT




RFH> One of my CS professors always insisted: "Do not reinvent the wheel -
RFH> If something works, just COPY it".

RFH> With that in mind, where can I find an algorithm/snippet that
RFH> converts:

RFH>  date --> week number

Read "man strftime" on nearest Unix-like system. This function supports a
few week number definitions according to different practice styles:

===
 %U    is replaced by the week number of the year (Sunday as the first day
       of the week) as a decimal number (00-53).

 %V    is replaced by the week number of the year (Monday as the first day
       of the week) as a decimal number (01-53).  If the week containing
       January 1 has four or more days in the new year, then it is week 1;
       otherwise it is the last week of the previous year, and the next
       week is week 1.

 %W    is replaced by the week number of the year (Monday as the first day
       of the week) as a decimal number (00-53).
===

Its sources can be got from any open source Unix clone.

RFH> and its inverse:
RFH>  week number --> date range

RFH> Just to make sure:

RFH> The year has 52 weeks, and their week numbers are: week 1, week 2,
RFH> week 3, etc.

This definition is incorrect: any year (supposing traditional
Gregorian calendar) has 52 full weeks and 1 partial, so if you start
with 1, Dec, 31 will always belong to week 53.

See above how to define week number in more useful way.

RFH> I believe that today (9/3/2009) we are in week number 36 of the year.

OK, but you should not be sure three days later.;)))


--netch--

Re: Looking for date algorithms

Postby gordonb.tlaeo » Fri, 04 Sep 2009 16:04:07 GMT

>One of my CS professors always insisted: "Do not reinvent the wheel -

Look at strftime(), and the conversions %U, %V, and %W.  There are
several definitions of week numbers there, one of which might
correspond with what you want.


That is an insufficient description.  And a year has more than 52 * 7
days in it.  It is possible that a year contains *54* weeks or partial
weeks.


The strftime conversions %U, %V, and %W return 35, 36, and 35, respectively
for the week number of 9/3/2009.


Re: Looking for date algorithms

Postby Rainer Weikusat » Fri, 04 Sep 2009 18:05:33 GMT

Ramon F Herrera < XXXX@XXXXX.COM > writes:

Even this CS professor would certainly be less than amused, should
everything in his household be the first at least remotely useful
result of an apprentice trying to build something :->. And the wheel
comparison is really stupid -- most human inventions are forgotten
after a couple of years. Considering that software has seriously been
developed for something like forty years know, who are 'we' to already
claim to have found all or even any of the 'ultimate answers'?

Re: Looking for date algorithms

Postby pjb » Fri, 04 Sep 2009 18:37:18 GMT

Ramon F Herrera < XXXX@XXXXX.COM > writes:


I'd agree with your professor, however there are a lot of algorithms
that are just plain wrong, notably concerning dates, out there.  You
might spend more time searching them and checking that they are
correct than writting one that is correct from scratch.

Of course, what you need is to know what makes a correct algorithm,
that is, you need to know the specifications, and in the case of date
algorithms, this is quite complex (that's why there are so many wrong
algorithms, they don't know the specificifications so they just make
them wrong).   So you'd better spend your time on searching the
problem of the calendars domain, so you can come with a correct
specification.  Then you will be able to write the algorithm easily
and correctly.



-- 
__Pascal Bourguignon__

Re: Looking for date algorithms

Postby Ramon F Herrera » Fri, 04 Sep 2009 23:43:29 GMT




 > The strftime conversions %U, %V, and %W
 > return 35, 36, and 35, respectively
 > for the week number of 9/3/2009.

I must add that I am interested in the "weeks" that begin on a Sunday
and end on the next Saturday. My first idea was to execute:

system("cal 2009");

and grab its output.  :-)

-Ramon


Re: Looking for date algorithms

Postby [Jongware] » Sat, 05 Sep 2009 05:29:11 GMT





That is, that way you can choose whether it will be "correct" this year only
(trivial), the next, oh, perhaps 3 years (Follow-up Q: why?), the next few
decades, or for all eternity to come (plus or minus a billion years). Perhaps
you'll get extra points for that last one.

[Jw]



Re: Looking for date algorithms

Postby phil-news-nospam » Sat, 05 Sep 2009 13:56:57 GMT


| 
| One of my CS professors always insisted: "Do not reinvent the wheel -
| If something works, just COPY it".
| 
| With that in mind, where can I find an algorithm/snippet that
| converts:
| 
| date --> week number
| 
| and its inverse:
| 
| week number --> date range
| 
| Just to make sure:
| 
| The year has 52 weeks, and their week numbers are: week 1, week 2,
| week 3, etc.

You also need to use the year number as part of the calculation when your
week number definition is not aligned to the beginning of the year (as is
the case for "start on Sunday" as you mention in a followup).  This gives
partial weeks and 54 of them more often than not (even if that week only
has one day in that year).  Some week counting rules start week 1 at the
first day of the year.  Some start it as the first week that has 7 days
and may treat the previous days as part of the last week of the previous
year or as week 0.  Week numbers tend to be used primarily as a business
tool, so you should find out what the exact rules are if that it what the
program is for.  If this is a generic exercise, pick a rule and define it
clearly.  I have implemented a bunch of date and time calculation code but
did not even try to do "week of year" because of the diverse rules that
vary by culture and businesses.  If I could quantify all the possible rules
I might try to do that some day.

-- 
-----------------------------------------------------------------------------
| Phil Howard KA9WGN       |  http://www.**--****.com/ ://ham.org/ |
| (first name) at ipal.net |  http://www.**--****.com/ ://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------

Re: Looking for date algorithms

Postby pjb » Sat, 05 Sep 2009 17:56:54 GMT

Ramon F Herrera < XXXX@XXXXX.COM > writes:


See, already you're wrong.

7*52 = 364, so you're already missing one or two days depending on
whether the year is leap or not.

More over, not all years start on a Monday (or Sunday, depending on
what day your week starts).

So yo already have eluded quite a number of complexities and
undespecifications...


-- 
__Pascal Bourguignon__

Re: Looking for date algorithms

Postby tm » Fri, 11 Sep 2009 19:49:38 GMT



See:  http://www.**--****.com/ #weekOfYear

If you want to use ISO 8601 week dates such as 2004-W53-6
you should take the following algorithms into account:

 http://www.**--****.com/ #weekDateYear
 http://www.**--****.com/ #weekDateWeek


Sorry, I don't have an algorithm for this problem at my hands.


Note that different countries have different conventions of how
to determine the week number. The algorithms mentioned above
use the ISO 8601 week numbers.

Greetings Thomas Mertes

Seed7 Homepage:   http://www.**--****.com/ 
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.

Re: Looking for date algorithms

Postby user923005 » Sat, 12 Sep 2009 09:43:23 GMT



There are several popular week numbers.
The simplest one is simply:
floor(day_of_year / 7) +1

There is a specific ISO week number:
 http://www.**--****.com/ 

These are also popular:
   Microsoft Excel function:
   =WEEKNUM(myDateVal,2)
   can be calculated as:
   =1+INT((myDateVal-(DATE(YEAR(myDateVal),1,2)-WEEKDAY(DATE(YEAR
(myDateVal),1,0))))/7)

   Microsoft Excel function:
   =WEEKNUM(myDateVal,1)
   can be calculated as:
   =1+INT((myDateVal-(DATE(YEAR(myDateVal),1,2)-WEEKDAY(DATE(YEAR
(myDateVal),1,1))))/7)

There are others besides.

The inverse will depend on what week function you choose.
You can always approximate and then search using your week() function.

Similar Threads:

1.woman looking for dating - Free Online Dating

2.need a date look here

3.Looking for C++ code to get file informations like file size, date created, etc

Looking for C++  code to get file informations like file size, date created, etc.
Any suggestions?

-Tamim

4.looking for up to date introduction to rpmbuild

Hallo group members.

Could You suggest me some good and up to date introduction to building/debugging rpms.

I am running fc.5 and I experienced some problems with some rpms. I am going to try to solve it on my own or at least ask some reasonable questions on that, that's why I need some understaning on how rpms are created and how to debug creation process. I found some documentation on that but it was either old (covered rpm version 3.0.5 - rpm only no rpmbuild) or long (book on 450 pages).

regards

5.need a date look here



Return to unix

 

Who is online

Users browsing this forum: No registered users and 34 guest