Author Topic: ISO Week Number  (Read 3348 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
ISO Week Number
« on: November 12, 2015, 04:10:11 AM »
Here is a Perl version that gets the current week number for the current date.

Code: Perl
  1. use DateTime;
  2.  
  3. print DateTime->now->week_number,"\n";
  4.  


jrs@laptop:~/Perl$ time perl weeknow.pl
46

real   0m0.118s
user   0m0.074s
sys   0m0.017s
jrs@laptop:~/Perl$


Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: ISO Week Number
« Reply #1 on: November 12, 2015, 04:59:28 PM »
Code: Text
  1. $Execon
  2.  
  3. Print Time$(11)

[riveraa@BLOSSOM ~/Projects/mbc/today] $ time ./weeknum
45

real   0m0.004s
user   0m0.001s
sys   0m0.002s

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: ISO Week Number
« Reply #2 on: November 12, 2015, 06:12:14 PM »
@AIR You seem to be behind a week.

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: ISO Week Number
« Reply #3 on: November 12, 2015, 06:43:58 PM »
No, first week of the year actually starts at zero.

from strftime C/C++ docs:

%U    week number in year 0053

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: ISO Week Number
« Reply #4 on: November 12, 2015, 06:46:38 PM »
That's not what the internet is telling me.  :o

Online AIR

  • RETIRED
  • BASIC Developer
  • Posts: 410
Re: ISO Week Number
« Reply #5 on: November 12, 2015, 07:03:21 PM »
Take this

Code: [Select]
my $weekNumber = POSIX::strftime("%V", gmtime time);
And change the V to U.

EDIT:

Try this for yourself
Code: Perl
  1. #!/usr/bin/env perl
  2.  
  3. use Posix;
  4.  
  5. print POSIX::strftime("%V", localtime time) . "\n";
  6. print POSIX::strftime("%U", localtime time) . "\n";
« Last Edit: November 12, 2015, 07:53:19 PM by AIR »

Offline John

  • Forum Support / SB Dev
  • Posts: 2191
    • ScriptBasic Open Source Project
Re: ISO Week Number
« Reply #6 on: November 12, 2015, 09:49:51 PM »

jrs@laptop:~/sb/sb22/perl$ perl airweek.pl
Can't locate Posix.pm in @INC (you may need to install the Posix module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at airweek.pl line 3.
BEGIN failed--compilation aborted at airweek.pl line 3.
jrs@laptop:~/sb/sb22/perl$


I did an update in CPAN which should have given me all the standard Perl modules.

I think this relates to the same problem I'm having with the SB Perl extension module. My Perl paths are FU'ed.

« Last Edit: November 12, 2015, 10:58:04 PM by John »