nisus.com
https://www.nisus.com/forum/

Wanted: Date/Time Macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=2438
Page 1 of 1

Author:  midwinter [ 2007-07-17 19:52:33 ]
Post subject:  Wanted: Date/Time Macro

Hi all.

I'm wondering if someone would take pity on me and create a date/time macro for me. Specifically, I'd like a macro that would produce this with a single click:

Wednesday, June 17, 2007
9:51 PM

I know that there is a date/time macro built in, but I can't make heads or tails of Perl.

Thanks in advance.

Cheers

Author:  martin [ 2007-07-18 00:07:13 ]
Post subject: 

Pity taken:

Code:
$fullDate = ''
$shortTime = ''

Begin Perl
   use POSIX qw(strftime);
   my $time = time;
   my @timestamp = localtime($time);
   
   my ($sec, $min, $hour, $day, $month, $year, $weekday) = localtime($time);
   $year += 1900;
   $monthName = strftime( '%B', @timestamp );
   $weekdayName = strftime( '%A', @timestamp );
   if( $hour > 12 ) {
      $hour -= 12;
   }
   elsif( 0 == $hour ) {
      $hour = 12; # for 12AM
   }
   $ampm = strftime( '%p', @timestamp );
   
   $fullDate = sprintf( '%s, %s %d, %04d', $weekdayName, $monthName, $day, $year );
   $shortTime = sprintf( '%d:%02d %s', $hour, $min, $ampm );
End

Type Text $fullDate
Type Newline
Type Text $shortTime

Author:  martin [ 2007-07-18 01:03:57 ]
Post subject: 

I've added this macro (and a couple more date/time formats) to the macro repository.

Author:  midwinter [ 2007-07-18 07:04:32 ]
Post subject: 

Thanks, Martin! Works like a charm! Exclamation point!

Author:  scottwhitlock [ 2007-07-18 07:10:11 ]
Post subject: 

Good to see you back, midwinter. I've missed the banana.

Author:  midwinter [ 2007-07-18 07:26:31 ]
Post subject: 

scottwhitlock wrote:
Good to see you back, midwinter. I've missed the banana.


Thanks, Scott. It was a crazy semester followed by a broken foot followed by a research trip to Europe.

But I'm back and writing again, so my plan is to bury Martin in feature requests for the upcoming Nisus Writer Super-Pro. ;)

Author:  martin [ 2007-07-31 22:44:54 ]
Post subject: 

midwinter found a bug in the macros I wrote. Basically all times in the 24th hour are printed as "00:MM AM" instead of "12:MM AM", eg: "00:55 AM" instead of "12:55 AM".

I've updated the macro files to fix this, so if you ever plan on writing in the midnight hour, it might be worth re-downloading them. Sorry everyone.

Author:  gemboy27 [ 2007-08-01 18:24:33 ]
Post subject:  Thanks

I haven't had a need for any of the macros, but I would just like to thank you for creating a page that has them on them

merci

please don't get your cape caught in the revolving door!!
http://s169.photobucket.com/albums/u202/librarymonkey27//monkey/niman.gif

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/