1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Days Until December 25

Discussion in 'T&T - Miscellaneous' started by Joe Caverly, Oct 15, 2009.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi,
    Here's a little item that I've added to my TCMD startup file;

    Code:
    statusbar %@execstr[powershell days2dec25.ps1]
    
    The days2dec25.ps1 Microsoft Powershell script is as follows;

    Code:
    "There are " + (([system.datetime]"25 december 2009").DayOfYear - `
    (get-date).DayOfYear) + " days until " + "25 December 2009"
    
    I can now see at a glance how many days until date x, in this case, December 25 2009.

    Joe
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    No need to invoke PowerShell; you can do the same calculation with @EVAL:

    Code:
    statusbar There are %@eval[%@doy[%_year-12-25] - %_doy] days until Christmas!
    
     
  3. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi Charles,
    Thankyou for the tip. I realize that this could be done just as easily in TCMD, but I wanted to demonstrate how easy it is to call a Microsoft Powershell script from TCMD.

    For simple solutions, such as this, I agree that yours is the better of the two. However, being able to access COM objects, including Database objects, directly from the command line, is a powerful feature of Microsoft Powershell, and one that can be a valuable tool for TCMD users.

    As Microsoft Powershell is touted to be the successor to VBScript, learning a little about Microsoft Powershell is a good thing, especially when it can augment TCMD.

    Joe
     
  4. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    176
    Likes Received:
    0
    There is of course, REXX. My appetite for REXX was whetted by JPSoftware recommending Quercus Rexx way back in the nineties. Still. the language is wonderful, and a lot of stuff on my pc gets maintained by Rexx scripts.

    The modern REXX 5.x versions are more powerful, the relevant line from the command prompt is;

    Code:
    [H:\USERS\wendy]rexxtry say date('b', '2011-12-25', 'i') - date('b')
    364
      ........................... L:\save\cdata\batch\rexxtry.cmd on WIN32
    
    REXXTRY comes from OS/2, is simply a command line wrapper for whatever REXX is. Even under OS/2, it checks the OS version to launch the correct help etc. This is evidently for next year, since it's boxing day, and australia is doing horrible in the cricket. With a little general programming, one can convert the string '2011-12-25' into a value to be calculated.
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    Here's another approach:

    unm.edu/~cdye/plugins/iso8601.html#f_days
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: Charles Dye
    To: ESFabian
    Sent: Sunday, 2010. December 26. 11:25
    Subject: RE: [T&T - Miscellaneous-t-1462] Re: Days Until December 25

    | Here's another approach:
    |
    | unm.edu/~cdye/plugins/iso8601.html#f_days

    Personally I prefer to stay within TCC without utilizing plugins when it can be done simply, so I like a variant of Charles' first post in this thread: %@eval[%@date[%_year-12-25] - %@date[%_date]]. Of course, for the purpose of testing the interface to REXX Wendy's method is best, just as Joe's shows how to use PowerShell. Charles' iso8601.dll has many features that are either not in TCC itself, or - as in the case at hand - more cumbersome to do without it.
    --
    Steve
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    It's elegant and easy to read, but have you tried it today?
     
  8. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: Charles Dye
    | Quote:
    | Originally Posted by Steve Fábián
    | Personally I prefer to stay within TCC without utilizing plugins when
    | it can be done simply, so I like a variant of Charles' first post in
    | this thread: %@eval[%@date[%_year-12-25] - %@date[%_date]].
    |
    | It's elegant and easy to read, but have you tried it today?
    ---- End Original Message ----
    No, I did not, because I knew when I wrote it that like your original version (using your @DOY and _DOY) it would fail in the last 6 days of each year. I considered making a test to detect that condition, but decided that it would make a "one-liner" awfully complicated. I ought to have included the warning: "Incorrect the last 6 days of every year!".
    Your function @DAYS, combined with your @NEXTDATE (as used in the @DAYS example for the exact issue starting this topic) is the only simple answer.
    You may consider adding to the @DAYS help topic an example using @EASTER[*] as well.
    --
    Steve
     
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    Well, this certainly isn't very elegant or readable:

    Code:
    set L=%@days[T,%@easter
    [*]]
    if %L gt 0 if %L lt 47 echo Today is the %@ord[%@eval[47 - %L]] day of Lent.
    
    Can you spot any issues or suggest improvements?
     
  10. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: Charles Dye
    | Quote:
    | Originally Posted by Steve Fábián
    | ---- Original Message ----
    | You may consider adding to the @DAYS help topic an example using
    | @EASTER[*] as well.
    |
    | Well, this certainly isn't very elegant or readable:
    |
    |
    | Code:
    | set L=%@days[T,%@easter[*]]
    | if %L gt 0 if %L lt 47 echo Today is the %@ord[%@eval[47 - %L]] day
    | of Lent.Can you spot any issues or suggest improvements?
    ---- End Original Message ----

    One example could be simply:

    echo %@days[T,%@easter[*]] days until Easter.

    For Lent I'd make it thus:

    set L=%@days[T,%@easter[*]]
    iff %L GE 47 then
    echo This is the %@ord[%@eval[%L-46]] day before Lent.
    elseiff %L lt 0
    echo This is the %@ord[strip[-,%L]] day after Lent.
    else
    echo Today is the %@ord[%@eval[47 - %L]] day of Lent.
    endiff

    Notes:
    1/ My calculation for "days until Lent" may be off by 1 day.

    2/ You might add (and I'd love to use) an enhanced "@IF" function:
    %@PLURAL[value,0-string,1-string,other_string]
    which would return the 0-string if value = 0, the 1-string if 0 < value <= 1, and the other_string if value is >1.

    3/ NOT TESTED! You should test it before publishing it (may need to play with your system date to test).
    --
    Steve
     
  11. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    I *do* have an @PLURAL, only I don't recall ever having posted that plugin...? IIRC, it only tested against 1 and -1; 0 is plural as far as I'm concerned.
     
  12. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: Charles Dye
    | Quote:
    | Originally Posted by Steve Fábián
    | 2/ You might add (and I'd love to use) an enhanced "@IF" function:
    | %@PLURAL[value,0-string,1-string,other_string]
    | which would return the 0-string if value = 0, the 1-string if 0 <
    | value <= 1, and the other_string if value is >1.
    |
    | I *do* have an @PLURAL, only I don't recall ever having posted that
    | plugin...? IIRC, it only tested against 1 and -1; 0 is plural as far
    | as I'm concerned.

    One might use a very different text when a value - esp. a count - is zero, e.g. the word NO. For example, "There are no more days before ...". When the value is negative, one might wish to display "It is already after ...".
    I have several batch programs (yes, I like to refer to them thusly - .com and .exe programs are also STORED as files, but never referred to as such) which make this distinction. I have also implemented a batch program version of your @ORD, and since your function became available discarded it.
    --
    Steve
     
  13. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,304
    Likes Received:
    39
    I've uploaded a fairly silly plugin:
    unm.edu/~cdye/plugins/numwords.html#f_plural

    Not sure that it's actually useful; this thing was just me playing with the plugin interface. I think you're asking for something more generic than my basic @PLURAL, a function to return one of several words/phrases depending on which of several ranges a number falls into. That seems like it could be pretty handy and might be a good fit for this plugin -- but I'd have to think about how it ought to look and work.
     
  14. K_Meinhard

    Joined:
    May 20, 2008
    Messages:
    310
    Likes Received:
    0
    Charles Dye wrote:


    Analogueous to CASE?

    herzliche Grüße,

    Klaus Meinhard
     
  15. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    176
    Likes Received:
    0
    With plural, ye may need to look at handling the dual case. In russian, apparently, the dual case is used for 2,3,and 4.
     

Share This Page