Welcome to APLNext Sign in | Join | Help
in
Community Website
Blogs Forums

⎕FMT is not working the same.

Last post 03-06-2007, 1:50 PM by Fred.Waid. 4 replies.
Sort Posts: Previous
  • ⎕FMT is not working the same.

     02-07-2007, 2:50 PM

     

    I’ve tried to replicate some DateTime formatting we’ve done in APLWIN.   In APLWIN it looks like:

         

       mo←3 9 6 8

       day←2 2 4 7

       yr←2001 2004 2005 2007

     

       'G¨99-¨,G¨99-¨,G¨9999 00:00:00.000¨' ⎕FMT (mo,[1.1]day),yr

    03-02-2001 00:00:00.000

    09-02-2004 00:00:00.000

    06-04-2005 00:00:00.000

    08-07-2007 00:00:00.000

     

    In VisualAPL’s Cielo Explorer I get:

     

       ⎕io←1

       mo←3 9 6 8

       day←2 2 4 7

       yr←2001 2004 2005 2007

     

       'G¨99-¨,G¨99-¨,G¨9999 00:00:00.000¨' ⎕FMT (mo,[1.1]day),yr

    G¨99-¨G¨99-¨G¨9999 00:00:03.000¨ G¨99-¨G¨99-¨G¨9999 00:00:02.000¨ G¨99-¨G¨99-¨G¨9999 00:20:01.000¨

    G¨99-¨G¨99-¨G¨9999 00:00:09.000¨ G¨99-¨G¨99-¨G¨9999 00:00:02.000¨ G¨99-¨G¨99-¨G¨9999 00:20:04.000¨

    G¨99-¨G¨99-¨G¨9999 00:00:06.000¨ G¨99-¨G¨99-¨G¨9999 00:00:04.000¨ G¨99-¨G¨99-¨G¨9999 00:20:05.000¨

    G¨99-¨G¨99-¨G¨9999 00:00:08.000¨ G¨99-¨G¨99-¨G¨9999 00:00:07.000¨ G¨99-¨G¨99-¨G¨9999 00:20:07.000¨

  • Re: ⎕FMT is not working the same.

     02-08-2007, 12:53 PM

    George,

    RC 5.0 contains the []CFMT system function, which supports a lot of the old formatting strings found in []FMT in legacy systems.

    The []FMT in Visual APL uses the standard .Net formatting strings for formatting your data. 

    This means that you can copy formatting strings from applications such as Microsoft Excel and use them to format your arrays in Visual APL.

    As it turns out, []FMT is a very powerful tool in .Net because it allows you to apply a formatting string across an entire array, or even apply a different formatting string to each element in an array.  Other .Net languages have no concept of arrays in this fashion, so we are rather proud that this is a feature unique to Visual APL.

    As for date formatting in Visual APL, there is a staggering ammount of functionallity available on the DateTime object in .Net, including date formatting!

    Here are some examples of formatting dates using []FMT in Visual APL:


           "d" ⎕fmt DateTime.Now

     7/27/2006

     

          "F" ⎕fmt DateTime.Now

     Thursday, July 27, 2006 12:33:47 PM


    The example above used the always available DateTime.Now object.  The next example here creates a DateTime with one of the dates you used in your example. 


          dt = DateTime(2007, 8, 7)
          dt
    8/7/2007 12:00:00 AM


          "d" ⎕fmt dt
     8/7/2007
         
          "F" ⎕fmt dt
     Tuesday, August 07, 2007 12:00:00 AM     

     


    There are many more built-in format strings for DateTime objects which you can use, or you can even create your own custom format strings which are composits of multiple date formatting strings.  The possibilities really are endless, and there are plenty of examples available on the internet. 

    For a base reference on what format strings you can use, and for more documentation on []FMT, just visit the Visual APL library located here:

    http://www.aplnext.com/library/aplnext/visual_aplnext.htm

    Once there, click the "Search" tab and search for "DateTime".

    Let me know if this helps, and if you need any help in making a custom format string for your date objects just post back here and we can easily put one together.

    Fred

     

     

  • Re: ⎕FMT is not working the same.

     02-08-2007, 5:36 PM

    George,

    The first format string in the example below will format a DateTime object just like in the example you gave in your post.  The format strings after that are just a few more ways to display the date using custom format strings:


    dt = DateTime.Now

    dt.ToString("MM-dd-yyyy hh:mm:ss.fffffff")

     

    02-08-2007 03:16:22.5623750

    dt.ToString("MM-dd-yyyy' 00:00:00.000'")

    02-08-2007 00:00:00.000

    dt.ToString("MMMM-dd-yyy")

    February-08-2007

    dt.ToString("MMM-dd-yyy")

    Feb-08-2007

     


     


    Another really neat feature of DateTime formatting in .Net is that the formatted strings that are produced can be culture specific.

    Here is an example of formatting a DateTime object in both the English and French culture:


     

    dt = DateTime.Now

    dt.ToString("MM-dd-yyyy hh:mm:ss.fffffff")

    02-08-2007 03:16:22.5623750

    dt.ToString("MM-dd-yyyy' 00:00:00.000'")

    02-08-2007 00:00:00.000

    dt.ToString("MMMM-dd-yyy")

    February-08-2007

    dt.ToString("MMM-dd-yyy")

    Feb-08-2007

     

     

    using System

    using System.Globalization

     

    dt = DateTime.Now

     

    ci = new CultureInfo("en-US")

    dt.ToString("f", ci.DateTimeFormat) // Format the DateTime with en-US localization

    Thursday, February 08, 2007 2:42 PM

     

    ci = new CultureInfo("fr-FR")

    dt.ToString("f", ci.DateTimeFormat) // Format the DateTime with fr-FR localization

    jeudi 8 février 2007 14:42

     

    dt.ToString("f", CultureInfo.CurrentCulture.DateTimeFormat) // Format the DateTime with the current localization of the system

    Thursday, February 08, 2007 2:42 PM

     

    dt.ToString("f") // if you do not specify the culture, it is by default the current system culture.

    Thursday, February 08, 2007 2:42 PM

     

     


    You can see that if you do not specify the specific culture to format your date with, the active default culture of the system is used.  This would mean that if your software is running on a computer running the German version of windows, your date formatting would automatically output a date in the format that the user was accustomed to seeing on his computer. 

    So, the bottom line here is that your date processing gains almost immeasurable versatility when you use the built in DateTime object instead of manageing the dates your self as just a vector of numbers. 

    And the best part is that you can use []FMT to apply any of the format strings above to any array in Visual APL.

    Fred

  • Re: ⎕FMT is not working the same.

     03-05-2007, 5:50 PM

    • Joined on 08-17-2006
    • Rockville, MD
    • Posts 6
    • Top 25 Contributor
    In version RC 5.x and 6.0,

            'G¨99-¨,G¨99-¨,G¨9999 00:00:00.000¨' ⎕CFMT (mo,[1.1]day),yr

    gives

    03-02-0000 00:20:01.000

    09-02-0000 00:20:04.000

    06-04-0000 00:20:05.000

    08-07-0000 00:20:07.000

    while in APL+Win, the result is

    03-02-2001 00:00:00.000
    09-02-2004 00:00:00.000
    06-04-2005 00:00:00.000
    08-07-2007 00:00:00.000

    This appears to be a bug in ⎕CFMT.

  • Re: ⎕FMT is not working the same.

     03-06-2007, 1:50 PM

    John,

    Thanks for finding this, we have it fixed now.

    Fred

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems