Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Working with javascript dates in web components

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Working with javascript dates in web components

    I've noticed several posts on the board expressing angst over using JavaScript dates in web components. The people on this board have helped me quite a bit over the years and I like to give back when I can. Below I�m going to outline some methods and properties that are very helpful with dealing with the issue of converting control data to and from JavaScript dates.

    Since JavaScript uses a zero based month, 0 being January, and a date format that a lot of world doesn�t use, it can be a real pain to work with dates that are entered in a component in another format. For instance, most of the world uses a dd/MM/yyyy format while the United States and JavaScript use MM/dd/yyyy. (JavaScript does accept some other formats as well but that isn�t the purpose of this discussion.) If you want to create a JavaScript date object using a standard A5 .getValue() method you're left with finding a way to reformat the string so that it can be passed into a JavaScript date constructor. Add into the mix the issue that the date field in the component can be formatted several other ways such as dd.mm.yy or yyyy/MM/dd and you really end up with a mess. To make it even more fun you can have a session variable that sets the formatting based on individual users so that now your code has to know what each user is using as their date format.

    Fortunately for us, the Alpha team has already had to deal with the same issues and has provided some easy ways to get these values into a JavaScript date object. My goal here is to point you to the properties and methods that make this easy. A5 has added two handy methods to the "stock" JavaScript Date object. The first .fromFormat(date as string,format as string) will set a JavaScript date object to the date specified in the date sting using the format string to specify the actual format. The format string is the standard A5 date/time formatting that is used in the Xbasic TIME( [ Format_String as C [, Date_Time_Value as T ]] ) function. I�ll cover the second method later in this post.

    For instance, if my control has a control with a date only date-picker, or a text control, with a date format of "dd/MM/yyyy" we can create a JavaScript date object very easily using code like this:
    Code:
    var dt = {dialog.object}.getValue('start_date');  //start_date is the name of the control in a UX with a date format of dd/MM/yyyy.  Grids work the same way.
    var mydate = new Date(); //instantiate the date object
    mydate.fromFormat(dt,"dd/MM/yyyy"); //sets the mydate object to the value in the control
    If you�re using a date/time picker your code might look like:
    Code:
    var dt = {dialog.object}.getValue('start_date');  //start_date is the name of the control in a UX that has been set up as a date-picker with a date/time format of dd/MM/yyyy 0h:0m am.
    var mydate = new Date(); //instantiate the date object
     mydate.fromFormat(dt,"dd/MM/yyyy 0h:0m am"); //sets the mydate object to the value in the control
    Pretty easy, isn't it? Now you might ask what if I'm using date-pickers for my controls and a session variable to set the date format so my international users all have their own formats. How can we find out the format dynamically? Again A5 has the solution. In the DOM on the user�s web browser A5 builds properties of the dialog or grid object that contain, among other things, the current format for date-picker fields. These properties are outlined below: (note the underscores where shown and note the field names must be in all caps)

    Code:
    {grid.object}._fieldHelpers_G.FIELD_NAME_IN_ALL_CAPS.dateTime.format  -- (Grid)
    {grid.object}._fieldHelpers_DV.FIELD_NAME_IN_ALL_CAPS.dateTime.format -- (Detail View)
    {grid.object}._fieldHelpers_S.FIELD_NAME_IN_ALL_CAPS.dateTime.format -- (Search Part)
    {dialog.object}.fieldHelpers.FIELD_NAME_IN_ALL_CAPS.dateTime.format -- (works in repeating section as well)
    To make the code above more universal, assuming we are using a date-picker, we can change it just a bit to use the actual format of the control, even though we may not know what it actually is.

    Code:
    var dt = {dialog.object}.getValue('start_date'); 
    var mydate = new Date(); 
    var unknownDateFormat = {dialog.object}.fieldHelpers.START_DATE.dateTime.format; //get the date/time format for this date picker.
    mydate.fromFormat(dt,unknownDateFormat);
    Finally to round it all up you may want to return a JavaScript date object back as a formatted string. In this case we can use A5's other addition to the JavaScript date object .toFormat(format as string)

    A complete JavaScript function for creating a JavaScript date object from a control and then returning a formatted date string back is shown below. It is used to set the low date for a date picker, in a second date picker control (end_date), to be one month more than the actual date set in the start_date control.

    Code:
    function lowDate() {[INDENT]/* This function will compute the low date shown in the Date Picker.
    The function must return a date value (using the Date format that the Date Picker is set to use).  */
    var dt = {dialog.object}.getValue('start_date');
    var dts = new Date();
    var dtFormat = {dialog.object}.fieldHelpers.START_DATE.dateTime.format //use this to ensure the formatting is universal (field name must be all caps)
    dts.fromFormat(dt,dtFormat);  
    dts.setMonth(dts.getMonth()+1); //set lowdate to start date plus one month minimum.
    return dts.toFormat(dtFormat); //use A5's toFormat() JavaScript addition to make the date formatting easier and to ensure we're sending back the same format as was received.
    [/INDENT]
    }
    Once you have the dates in a JavaScript object then math operations are straight forward and there are lots of resources available on the internet, complete with examples .

    I hope this has been of help in taking some of the mystery out of using JavaScript date objects with A5 web components.
    Jim Coltz
    Alpha Custom Database Solutions, LLC
    A5CustomSolutions.com
    [email protected]

    #2
    Re: Working with javascript dates in web components

    What an informative and generous post, Jim. Thank you.
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    Comment


      #3
      Re: Working with javascript dates in web components

      Originally posted by kingcarol View Post
      What an informative and generous post, Jim. Thank you.
      Yea, what she said...
      Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

      Comment


        #4
        Re: Working with javascript dates in web components

        Thanks Jim.

        Comment


          #5
          Re: Working with javascript dates in web components

          Thanks for the info friend, I have a JavaScript date equivalent of a DateTime (how many milliseconds have passed between now and the beginning of 1970), so all I get is a number, how could I format that field to a human datetime?

          Thanks,
          Juan Silva
          My Small Bizz, LLC
          sigpic

          Comment


            #6
            Re: Working with javascript dates in web components

            JavaScript
            new Date(that number);
            Should give you the human date
            Then you should be able to use date.toFormat in alpha
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: Working with javascript dates in web components

              What a truly class act you are Jim. Thank you for sharing such a great post.
              If our paths ever cross, I will be buying you a beer my friend.
              Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

              Comment

              Working...
              X