Results 1 to 13 of 13
  1.    #1  
    Date functions make me giddy - I have searched through these forums and the documentation but am getting stuck with the commands in Ares.
    Anyway I have a Datepicker which sets startdate
    There is a text field - length - which sets a duration in days
    I would like to calculate a new date, enddate which is startdate + length and then place this in a result textfield.

    Can someone please help correct this noob? Many thanks in advance

    calcTap: function(inSender, event) {
    var duration = 0;
    var enddate = this.$.startdate.getDate();
    duration = this.controller.get("length").mojo.getValue();
    // enddate.setDate(enddate.getDate()+ duration); // this does not work
    this.controller.get("result").mojo.setText(enddate);
    }
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  2. #2  
    Quote Originally Posted by palmdoc2005 View Post
    Date functions make me giddy - I have searched through these forums and the documentation but am getting stuck with the commands in Ares.
    Anyway I have a Datepicker which sets startdate
    There is a text field - length - which sets a duration in days
    I would like to calculate a new date, enddate which is startdate + length and then place this in a result textfield.

    Can someone please help correct this noob? Many thanks in advance
    Might I recommend:

    Code:
    calcTap: function(inSender, event) {
    var duration = 0;
    duration = this.controller.get("length").mojo.getValue();
    var currentTime = new Date().getTime();
    var durationInMS = duration * 1000 * 60 * 60 * 24; // 1 day in milliseconds
    var enddate = new Date(currentTime + durationInMS); // just the object, you still need to turn this into a date
    this.controller.get("result").mojo.setText(enddate.toString()); // outputs long string showing the full end date
    }
    It is best to read up on the native Date() object:
    JavaScript Date Object
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup
  3.    #3  
    Hi Arthur
    Thank for the pointers but I am still confused
    Wouldn't
    var currentTime = new Date().getTime();
    mean setting it only to the current time?

    How does one set to to the Date which is set in the Date picker (which has the name startdate) ?

    Thanks

    What I hope to do is to come up with a simple app which will help one compute the date X days from a set date. I find I often need to do this when setting appointments X days or weeks from a particular date.

    Appending a screenshot of the basic design in Ares
    Attached Images Attached Images
    Last edited by palmdoc2005; 05/10/2010 at 09:27 AM.
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  4.    #4  
    OK I explored it a bit further but am stuck, crucially in not being able to read in the new date from the Date picker.
    I entered dateModel as the model name in the model properties of the date picker in Aries

    Anyway here is the code in the main assistant
    calcTap: function(inSender, event) {
    var duration = 0;
    duration = this.controller.get("length").mojo.getValue();
    var settime = this.dateModel.date; //can't get it to recognise date set in date picker
    var currentTime = new Date();
    currentTime = settime.getTime();
    var durationInMS = duration * 1000 * 60 * 60 * 24; // 1 day in milliseconds
    var enddate = new Date(currentTime + durationInMS); // just the object, you still need to turn this into a date
    enddate = enddate.toLocaleString("ddd M/d/yyyy");// how come this does not work?
    this.controller.get("result").mojo.setText(enddate.toLocaleString("ddd M/d/yyyy"));
    }
    I attach the whole Aries project if anyone cares to help. Thanks.
    Attached Files Attached Files
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  5. #5  
    Hey palmdoc,

    The way I did it follows. Granted I only did it for time, I'm sure you can add a few things here to do days instead.

    I began by declaring the time extracted from the time picker and putting it into a variable. I have other reasons for doing this, but just thought I'd show it to show the flow of information.
    Code:
    Form = {
            STime: stimeModel.time,
    	ETime: etimeModel.time,
    };
    Convert the format of the date into a short form which cleans it up a bit, and then separate the hours and minutes for display (this is optional but I assume you want it to look nice when you display it):
    Code:
    STime = Mojo.Format.formatDate(Form.STime,'short');
    ETime = Mojo.Format.formatDate(Form.ETime,'short');
    Form.STime = STime.split(" ")[1] + " " + STime.split(" ")[2];
    Form.ETime = ETime.split(" ")[1] + " " + ETime.split(" ")[2];
    Form.Date = STime.split(" ")[0];
    This extracts specific time from the picker, I'm assuming instead of getTime() you can use getDay() or other such functions that can help extract the desired piece of information from the picker itself. Then you can conduct a simple subtraction to get the difference. I've noticed these calculations are actually smart and tend to be able to do most of the hard work themselves:
    Code:
    startTimer = stimeModel.time.getTime();
    endTimer = etimeModel.time.getTime();
    timeDiff = endTimer - startTimer;
    timeDiffM = Math.floor((timeDiff/1000)/60);
    timeDiffH = Math.floor(timeDiffM / 60);
    timeDiffMin = Math.floor(timeDiffM % 60);
    I have certain calculations afterward to convert milliseconds to seconds, minutes, and hours and such, ofcourse you might not need that, but just in case you do, they are here for your reference.

    I'm not sure if I answered your question or not, but I sure tried!

    Good Luck!
    Last edited by SirataXero; 05/10/2010 at 05:58 PM.
  6.    #6  
    Thanks SirataXero
    My basic dilemma is how to read in the date from
    the Date Picker in Ares, and then use that value for date calculations.

    If the settings for Date Picker in Ares are as follows
    under COMMON:
    name = startdate
    label = Start Date
    under MODEL:
    modelName = dateModel
    datePropertyName = value

    In the main assistant, how does one read in the date?
    The documentation is honestly hard to figure out and there are not enough examples for beginners.

    Ok let's say we are trying to set enddate to that set by the user using the Date Picker
    I tried:
    var enddate = this.startdate.date;
    but it doesn't seem to work

    Help appreciated.
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  7. #7  
    Since i'm not sure how the whole "this.x" works, I tend to disassociate my models from the this. You can very easily declare a model as a variable without "binding" it to a "this." statement. This prevents confusion when you refer to it from another function (at least for me, i'm sure someone who actually knows how to use it has no problem).

    Also, try something like startdate.getDay() and see if that works. I don't know if you can pull the date out by just saying startdate.date.
  8.    #8  
    Sigh. startdate is the name of the Date Picker under COMMON in Ares
    In order to pull the date value I have tried without success:
    var enddate = this.startdate.date;
    var enddate = this.startdate.getDate();
    var enddate = this.startdate.getDay();

    What does work is this:
    var enddate = this.$.startdate.getDate(); //can anyone explain more? thanks

    I managed to figure out how to use it in the calculation. Can someone help how to format it to only the day/date and not the time?

    Anyway here is the code placed in MainAssistant in Ares:

    Code:
    	calcTap: function(inSender, event) {
    		var duration = 0;
    		duration = this.controller.get("length").mojo.getValue();
    		var enddate = this.$.startdate.getDate();
    		enddate = new Date(enddate);
    		currentTime = enddate.getTime();
    		var durationInMS = duration * 1000 * 60 * 60 * 24; // 1 day in milliseconds
    		var enddate = new Date(currentTime + durationInMS); // just the object, you still need to turn this into a date
    		enddate = enddate.toLocaleString("ddd M/d/yyyy");// how come this does not work?
    		this.controller.get("result").mojo.setText(enddate); 
    	}
    Last edited by palmdoc2005; 05/10/2010 at 06:44 PM.
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  9.    #9  
    Here's another working way to fish out the date from Datepicker, with the settings under MODEL in the Datepicker properties in Ares:
    modelName - dateModel
    datepropertyname - date

    Code:
       calcTap: function(inSender, event) {
          var duration = 0;
          duration = this.controller.get("length").mojo.getValue();
          var enddate = this.dateModel.date; //under MODEL for the Datepicker
          currentTime = enddate.getTime();
          var durationInMS = duration * 1000 * 60 * 60 * 24; // 1 day in milliseconds
          var enddate = new Date(currentTime + durationInMS); 
          enddate = enddate.toLocaleString("ddd M/d/yyyy");// how come this does not work?
          this.controller.get("result").mojo.setText(enddate);
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  10.    #10  
    and finally got the formatting right

    Code:
    calcTap: function(inSender, event) {
          var duration = 0;
          duration = this.controller.get("length").mojo.getValue();
          var enddate = this.dateModel.date; //under MODEL for the Datepicker
          currentTime = enddate.getTime();
          var durationInMS = duration * 1000 * 60 * 60 * 24; // 1 day in milliseconds
          var enddate = new Date(currentTime + durationInMS); 
          enddate = enddate.toDateString("ddd M/d/yyyy");
          this.controller.get("result").mojo.setText(enddate);
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  11.    #11  
    Ok replaced the duration entry with an Integer Picker widget.
    The app at this stage looks like the screenshot below.
    What I'd like to do next is with the calculated projected Date, open the Calendar and create a new Calendar event. Any tips here?

    Thanks
    Attached Images Attached Images
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  12.    #12  
    Attaching the ipk for Datecalc if anyone cares to try
    Attached Files Attached Files
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  13.    #13  
    OK, I have completed the basic app, ditched the create Calendar event idea for now (its too complicated for me) and published it as a Web app.
    Further discussion in this thread:

    http://forums.precentral.net/showthread.php?p=2445421
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News

Posting Permissions