28 Replies Latest reply on Dec 17, 2006 6:49 AM by Newsgroup_User

    cast UTC

    Keith444
      Hi can someone help me i have 2 list boxes

      1. Times = 08:00:00
      2. Date = 12/12/2006

      i need to convert this 2 list boxes to a datetime format then i need to convert the datetime to the server time, i have been told i need to cast it to UTC,

      but not sure how to do this, any example code would be good

      Many thanks

      Keith
        • 1. Re: cast UTC
          Level 7
          Keith444 wrote:
          > Hi can someone help me i have 2 list boxes
          >
          > 1. Times = 08:00:00
          > 2. Date = 12/12/2006
          >
          > i need to convert this 2 list boxes to a datetime format then i need to
          > convert the datetime to the server time, i have been told i need to cast it to
          > UTC,
          >
          > but not sure how to do this, any example code would be good


          <cfscript>
          aTime="08:00:00";
          aDate="12/12/2006";

          // long way round
          hour=listFirst(aTime,":");
          minute=listGetAt(aTime,2,":");
          second=listLast(aTime,":");
          // you need to know your locale here, which came first, chicken or egg?
          // assumming m/d/y, ie en_US
          year=listLast(aDate,"/");
          month=listFirst(aDate,"/");
          day=listGetAt(aDate,2,"/");
          aRealDate=createDateTime(year,month,day,hour,minute,second);
          writeoutput("long way round:=#aRealDate#<br>");

          //shortcut, again you still need to know locale
          anotherDate=lsParseDateTime(aDate);
          hours=hour+minute/60+second/360;
          anotherRealDate=dateAdd("h",hours,anotherDate);
          writeoutput("shortcut:=#anotherRealDate#");
          </cfscript>
          • 2. Re: cast UTC
            Keith444 Level 1
            Hi Many thanks,

            where you say "you need to know your locale here"

            will this be the server locale or the locale time of the user?

            if its the user i can get the user to select a time zone and have it stored in my database, if i do this what value would enter to my table?

            • 3. Re: cast UTC
              Level 7
              Keith444 wrote:
              > where you say "you need to know your locale here"
              > will this be the server locale or the locale time of the user?

              user.

              > if its the user i can get the user to select a time zone and have it stored in
              > my database, if i do this what value would enter to my table?

              still need to know the date format you're showing to them.
              • 4. Re: cast UTC
                MikerRoo Level 1
                It doesn't have to be this complicated!
                The CRITICAL thing, as Paul has hinted, is that you understand the date syntax the USER is using (mm/dd/yy, dd/mm/yy, etc.) and that you know and store the user's timezone offset.

                See the attached.

                • 5. Re: cast UTC
                  Level 7
                  MikerRoo wrote:
                  > It doesn't have to be this complicated!
                  > The CRITICAL thing, as Paul has hinted, is that you understand the date syntax
                  > the USER is using (mm/dd/yy, dd/mm/yy, etc.) and that you know and store the
                  > user's timezone offset.

                  once again, "no". you cannot simply store the offset. you need to manage the
                  complete timezone, otherwise DST differences will eventually bite you.

                  • 6. Re: cast UTC
                    Keith444 Level 1
                    ok Paul,

                    the user has to list boxes with time format of hh:mm & date format dd/mm/yyyy

                    but what do i need to store in my table for the users time zone?

                    so say if user Craig has a time zone of Melbourne Australia, and i have a column in my table called timezone for each user what goes in there?
                    • 7. Re: cast UTC
                      Level 7
                      Keith444 wrote:
                      > but what do i need to store in my table for the users time zone?

                      their chosen tz id. i've used the latest icu4j lib to pull out tz IDs by
                      country, you can grab the CSV data from:

                      http://www.susteinableGIS.com/projects/tz/tzByCountry.zip

                      push that data into your database, when you offer tz choices to your users,
                      select the tz from that table by country. for instance this gets all the tz for
                      australia:

                      <cfquery datasource="lab" name="tz">
                      SELECT timezone
                      FROM timezones
                      WHERE countryISO3166='AU'
                      </cfquery>

                      then use the tz ID they choose in the timezone CFC i mentioned in one of your
                      other threads.
                      • 8. Re: cast UTC
                        Level 7
                        PaulH **AdobeCommunityExpert** wrote:
                        > http://www.susteinableGIS.com/projects/tz/tzByCountry.zip

                        i really should learn to spell, that should be:

                        http://www.sustainablegis.com/projects/tz/tzByCountry.zip
                        • 9. Re: cast UTC
                          MikerRoo Level 1
                          quote:

                          Originally posted by: Newsgroup User
                          once again, "no". you cannot simply store the offset. you need to manage the
                          complete timezone, otherwise DST differences will eventually bite you.




                          Not really. The simple system is good enough 98% of the time. Maybe there is a small chance that it won't work for a few days for a few oddballs (odds are, non of the OP's customers). But, then again, those oddballs will be used to it (rather like "Tonee" always having to correct others on how her name is spelled) so no real damage there.

                          You've already given the OP your CFC system -- which is the smart and more correct way to go. He resisted.
                          Barring that, the simple system is better than most web sites and quite likely good enough.
                          • 10. cast UTC
                            BKBK Adobe Community Professional & MVP
                            > say if user Craig has a time zone of Melbourne Australia, and i have a column in
                            > my table called timezone for each user what goes in there?

                            Remember that timezone is not just one property, but a set of properties, including offset, daylight savings, and so on.

                            Your "Melbourne Australia" amounts to the timezone ID called "Australia/Melbourne". So, I would convert the column's name to timezoneID instead.

                            You will get the list of timezone IDs by running

                            <cfset tz_id=createobject("java", "java.util.TimeZone").getAvailableIDs()>
                            <cfdump var="#tz_id#">

                            You will get the timezone information for the ID "Australia/Melbourne" by running

                            <cfset tz=createobject("java", "java.util.TimeZone").getTimeZone("Australia/Melbourne")>
                            <cfoutput>#tz#</cfoutput>


                            • 11. Re: cast UTC
                              Level 7
                              MikerRoo wrote:
                              > Not really. The simple system is good enough 98% of the time. Maybe there

                              mike that's not good advice. if you're bothering w/timezone at all, then all DST
                              differences *are* important. coming from australia (i guess) i'd think you'd get
                              it more than most folks (DST changes to accommodate TV for the commonwealth
                              games, the recent WA "oops" tz changes, etc.).

                              at least i dug out the tz by country data ;-) maybe somebody will find that useful.

                              • 12. Re: cast UTC
                                MikerRoo Level 1
                                You're right. I just thought that since OP wasn't seeming to grok the 100% solution (with free CFC's already built) that a "close enough" solution would get him further along the the desired path.

                                I withdraw the suggestion, above.
                                • 13. Re: cast UTC
                                  Keith444 Level 1
                                  ok many thanlks paul nearly there i think?

                                  if you look at url www.thesmsengine.com/times.cfm

                                  is this ok for formats?

                                  if so what will i need to put on my action page to convert this to server time

                                  many thanks once again

                                  Keith
                                  • 14. Re: cast UTC
                                    Level 7
                                    Keith444 wrote:
                                    > <td><select name="times">

                                    terrible var name for timezones....


                                    <cfscript>
                                    // or wherever you put the timezone CFC
                                    tz=createObject("component","cfc.i18n.timeZone");
                                    // assuming this is user's locale, you need to manage these
                                    setLocale("en_AU");
                                    smsDate=lsParseDateTime(form.SMS_Date);
                                    hours=listFirst(SMS_Time,":")+listGetAt(SMS_Time,2,":")/60+listLast(SMS_Time,":")/360;
                                    smsDate=dateAdd("h",hours,smsDate);
                                    // shortcut method i forgot about
                                    serverDate=tz.castToServer(smsDate,form.times);
                                    </cfscript>
                                    • 15. cast UTC
                                      Keith444 Level 1
                                      ok yes i changed it from times to converttimes


                                      what will be the varible the i can insert into my table as the server time?

                                      will it be ServerDate

                                      many thanks
                                      • 16. Re: cast UTC
                                        Level 7
                                        Keith444 wrote:
                                        > will it be ServerDate

                                        yes.
                                        • 17. Re: cast UTC
                                          Level 7
                                          "or wherever you put the timezone CFC"

                                          Could not find the ColdFusion Component cfc.i18n.timeZone.
                                          • 18. Re: cast UTC
                                            Keith444 Level 1
                                            still dont understand, i have uploaded the timezone.cfc

                                            what else do i need to do
                                            • 19. Re: cast UTC
                                              Level 7
                                              Keith444 wrote:
                                              > still dont understand, i have uploaded the timezone.cfc

                                              where?

                                              in the case of the example, "cfc.i18n.timeZone", "cfc" is a cf mapped dir
                                              pointing at "c:\cfc\"

                                              that cfc is in c:\cfc\i18n\timezone.cfc & referred to in cf programs as
                                              cfc.i18n.timezone

                                              you can put the cfc anywhere you want as long as you & cf know. if you don't
                                              want to bother w/cf map dir, put the cfc in the same dir as the page calling it
                                              & simple refer to it as "timezone":

                                              tz=createObject("component","timeZone");
                                              • 20. cast UTC
                                                Keith444 Level 1
                                                ok yes sorted it, now i just need to set my local

                                                at the min it is "2en_AU"

                                                does this need to be the server local time? if so i need this to be brisbane/australia i have tried it but dont work any ideas

                                                or

                                                does it need to be the users local? if so what value do i need from the timezone list box?
                                                • 21. Re: cast UTC
                                                  tooMuchTrouble Level 3
                                                  the locale needs to be a java or cf standard locale ID such as "en_AU" not something you made up yourself.

                                                  not following the rest of your question.
                                                  • 22. cast UTC
                                                    Keith444 Level 1
                                                    ok so what is the cf standard for brisbane australia

                                                    just not sure where the form element coneverttime comes into the action page? thought i need to know what timezone the user is in?

                                                    <select name="converttimes">
                                                    <cfoutput query="tz">
                                                    <option value="#tz.timezone#">#tz.timezone#</option>
                                                    </cfoutput>
                                                    </select>
                                                    • 23. Re: cast UTC
                                                      Level 7
                                                      Keith444 wrote:
                                                      > ok so what is the cf standard for brisbane australia

                                                      you are confusing locale & timezone (tz). from what you've posted before you
                                                      need both. locale to handle the date string parsing. tz to handle, well, timezones.
                                                      • 24. Re: cast UTC
                                                        BKBK Adobe Community Professional & MVP
                                                        > ok so what is the cf standard for brisbane australia
                                                        Didn't you see what I wrote in answer to your similar question about Melbourne?

                                                        • 25. cast UTC
                                                          Keith444 Level 1
                                                          ok can u have a look at

                                                          to see what the error is? i cant work it out
                                                          • 26. cast UTC
                                                            BKBK Adobe Community Professional & MVP
                                                            I did your test. You're right. Coldfusion seems to complain that "en_AU" is not a valid value for locale.

                                                            To confuse matters even more, the error message tells you "The list of supported locales is stored in the variable Server.ColdFusion.SupportedLocales." Yet if you do

                                                            <cfdump var="#Server.ColdFusion.SupportedLocales#">

                                                            you will see that en_AU is among the list of locales. I think the problem arises because Coldfusion uses the JVM locales by default, even though it has its own. More on this in the liveDocs for setLocale().

                                                            What then if you just use the JVM version instead, i. e.

                                                            setLocale("English (Australian)"); //Mind space between English and (Australian)



                                                            • 27. cast UTC
                                                              Keith444 Level 1
                                                              ok that worked

                                                              Many Thanks
                                                              • 28. Re: cast UTC
                                                                Level 7
                                                                Keith444 wrote:
                                                                > ok that worked but, but dont understand why it is English (Australian)

                                                                it represents a locale. starting w/cf 7.x cf locales are java locales.

                                                                > what does this represent, the users location or the servers location?

                                                                from what yo posted before, the user's locale NOT *just* their location but the
                                                                language, the ways they format dates, currency, etc.

                                                                > does this need to change for different users?

                                                                do you have users w/different locales?

                                                                > also i am now getting a date format error any ideas can u have a look at the
                                                                > url again

                                                                it now says you're missing the tz data (which you are).