Alpha Video Training
Results 1 to 2 of 2

Thread: Alpha JS Date functions: fromFormat(value,format) & toFormat(format)

  1. #1
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,301

    Default Alpha JS Date functions: fromFormat(value,format) & toFormat(format)

    I just wasted a lot of time on MDN trying to find documentation on these. Aaaah. Jokes on me. They're Alpha's. They extend the Date object in JS:

    fromFormat(value,format) : So, you give it a value, like "8 AM" or "12-12" and a format, like "0h:0m A" or "dd/MM/yyyy", and it sets the Date.

    toFormat(format) : Give it a format, and you get the date back - parsed in that format.

    Code:
    var d = new Date();
    console.log(d); 
    d.fromFormat("12-11-10","yy-MM-dd")
    console.log(d);
    var s = d.toFormat("MM/weekday/yyyy")
    console.log(s);
    Here's what I get running that code in console:
    > Fri Sep 13 2013 16:11:39 GMT-0400 (Eastern Daylight Time)
    > Sat Nov 10 2012 16:11:39 GMT-0500 (Eastern Standard Time)
    > "11/saturday/2012"


    I'm not sure what all of your format options are. But I have a hunch that it uses the date & time format specification: http://wiki.alphasoftware.com/~alpha...ormat+Elements

    Anyone else use these?
    Alpha Five Version 11 Build 3381-4096
    Alpha Anywhere Version 12.3 Build 2614-4409
    Find me on Github!

  2. #2
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,301

    Default Re: Alpha JS Date functions: fromFormat(value,format) & toFormat(format)

    So, I applied those functions in the onBlur event for some Time text boxes in a repeating section so they auto-update/format after the user puts stuff in them.

    onBlur event for my text box:
    Code:
    parseTime({dialog.Object},'LOGGER','START_TIME');
    And my parseTime function:
    Code:
    var parseTime = function (dlg,repSec,field) {
    	var timeFormat = "0h:0m AM";
    	repSec = repSec.toUpperCase();
    	field = field.toUpperCase();
    	var row = dlg.getRepeatingSectionActiveRow(repSec);
    	if (row != false) {
    		var d = new Date(2000,1,1);
    		var val = dlg.getValue(field+':'+row);
    		if (val === "") {
    		        // Value is blank. Don't format it to 12:00 AM.
    			return;
    		}
    		d.fromFormat(val,timeFormat);
    		val = d.toFormat(timeFormat);
    		dlg.setValue(field+':'+row,val,false);
    	}
    }
    Some answers for some of the WHY:

    var d = new Date(2000,1,1) : This sets the date to Feb 1, 2000 at 12:00:00 AM. You want the time portion to be zero (12:00:00 AM) because when you get the value from the control, if the user entered something like 4 PM, you want that to parse out to 4:00 PM, not 4:13 PM - where "13" comes from the fact that you Date initialized to September 13, 2013 6:13:22 PM.

    toUpperCase() : Just in case I was dumb and didn't pass it in right.

    function (dlg,repSec,field) : I intend to use this dialog in more than one place where two instances can exist simultaneously. Passing in {dialog.object} ensures that the data is fetched & set in the correct dialog - ie, the one the user is actively using.

    I suppose you could use the Mask stuff. I've not figured out how to make that work, though, such that you can type in any of the following and have it work: "4pm", "9:30 am", "10 15", "14:20", or "01:11 AM".

    ---
    Sarah
    Alpha Five Version 11 Build 3381-4096
    Alpha Anywhere Version 12.3 Build 2614-4409
    Find me on Github!

Similar Threads

  1. UX - repeating section not saving date values -??? date format issue?
    By RIckyRel in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 11-12-2013, 02:58 PM
  2. Date Range Fields in Search doesnt respect Grid Properties Date Format or Textbox For
    By aburningflame in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 04-25-2011, 12:38 PM
  3. Field display format other than actual format
    By randosui in forum Application Server Version 10 - Web/Browser Applications
    Replies: 3
    Last Post: 11-15-2010, 01:53 AM
  4. Change Date field from a character format to a Date format
    By Billn in forum Alpha Five Version 10 - Desktop Applications
    Replies: 11
    Last Post: 07-18-2010, 12:11 PM
  5. Date format, Alpha 5 v.10 (general)
    By cFlat7 in forum Alpha Five Version 10 - Desktop Applications
    Replies: 5
    Last Post: 05-09-2010, 10:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •