So yeah I was substringing date.toString, not a good idea. I changed it to 
be more consistent as shown below, but I still have a weird issue, day of 
the week seems to be 2 days out:

 int DAY_OF_WEEK = cal.get(java.util.Calendar.DAY_OF_WEEK);
switch(DAY_OF_WEEK)
            {
                case 0: dayName="Mon";break;
                case 1: dayName="Tue";break;
                case 2: dayName="Wed";break;
                case 3: dayName="Thu";break;
                case 4: dayName="Fri";break;
                case 5: dayName="Sat";break;
                case 6: dayName="Sun";break;
            }

tells me aug 31 2018 was sunday, but it was friday?
even if I start at case 1: its still one day out, whats happening? sure ive 
been thru this so many times.

SimpleDateFormat dateTodaySDF = new SimpleDateFormat("yyyy-MM-dd");
        Date dateToday = null; //a date object representing the string they 
passed in
        try {
            dateToday   = dateTodaySDF.parse(stringDate);
            _("dateToday -> "+dateToday.toString());
            //do this purely in cn1 so its same on ios and android, no 
toString stuff on dates
            java.util.Calendar cal = java.util.Calendar.getInstance();     
            cal.setTime(dateToday); 
            
            int DAY_OF_WEEK = cal.get(java.util.Calendar.DAY_OF_WEEK);
            int DAY_OF_MONTH = cal.get(java.util.Calendar.DAY_OF_MONTH);   
            switch(DAY_OF_WEEK)
            {
                case 0: dayName="Mon";break;
                case 1: dayName="Tue";break;
                case 2: dayName="Wed";break;
                case 3: dayName="Thu";break;
                case 4: dayName="Fri";break;
                case 5: dayName="Sat";break;
                case 6: dayName="Sun";break;
            }
            dayDate=""+DAY_OF_MONTH;
            _("DAY_OF_WEEK  ->"+dayName);
            _("DAY_OF_MONTH ->"+DAY_OF_MONTH);
            int MONTH = cal.get(java.util.Calendar.MONTH);
            switch(MONTH)
            {
                case 0: monthName="Jan";break;
                case 1: monthName="Feb";break;
                case 2: monthName="Mar";break;
                case 3: monthName="Apr";break;
                case 4: monthName="May";break;
                case 5: monthName="Jun";break;
                case 6: monthName="Jul";break;
                case 7: monthName="Aug";break;
                case 8: monthName="Sep";break;
                case 9: monthName="Oct";break;
                case 10: monthName="Nov";break;
                case 11: monthName="Dec";break;
            }
            _("MONTH ->"+monthName);
            monthNumber=(MONTH+1)+"";
            _("monthNumber-> "+monthNumber);
            _("So the date passed in was: "+dayName+", "+DAY_OF_MONTH+" of 
"+monthName);

On Friday, March 29, 2019 at 6:56:13 PM UTC+8, Gareth Murfin wrote:
>
> this code runs fine on android and emulator  from my test it produces:
> "dateTodayS: Fri Aug 31, dayName: Fri monthName: Aug, dayDate: 31, 
> monthNumber:08",
>
> but on real ios it produces:
>
> "dateTodayS: August 31, dayName: Aug monthName: st, dayDate: 1, 
> monthNumber:08",
>
> I realise its just parsing different because of the result from parsing 
> the date, but shouldnt it behave identically on all platforms?
>
>
> _("DateStringHolder received "+stringDate);
>         SimpleDateFormat dateTodaySDF = new SimpleDateFormat("yyyy-MM-dd");
>         Date dateToday = null; //a date object representing the string 
> they passed in
>         try {
>             dateToday   = dateTodaySDF.parse(stringDate);
>             String dateTodayS = dateToday.toString();
>             dayName    = dateTodayS.substring(0,3);
>             monthName  = dateTodayS.substring(4,7);
>             dayDate    = dateTodayS.substring(8,10);            
>             monthNumber= stringDate.substring(5,7);
>             
>             //for testing differences on ios and android!
>             Dialog.show("ios debug", "dateTodayS:"+dateTodayS+", 
> dayName:"+dayName+", monthName:"+monthName+", dayDate:"+dayDate+", 
> monthNumber:"+monthNumber, "OK", "Cancel");
>         }
>         catch(Exception e)
>         {
>             _("**warning** cant parse date! "+e.getMessage()+" 
> ->"+stringDate);
>             e.printStackTrace();
>         }
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/3d346548-522a-4c2d-8ad0-0274b289a07e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to