Format of Times

Hello all,

I am brand new to Xojo and my goal is to build a custom scheduling and budgeting app for mac, windows and perhaps the web. A key component of this is being able to have my users enter times on a schedule with as few keystrokes as possible. I don’t really want to use pull down menus for this. I want times to be entered into text fields that then automatically format the text to the desired format.

A lot of this work is currently being done in Excel, and there the user can enter “7:30 p” and the software automatically sets the field to “7:30 PM” Even better would be if the user could enter “730p” and have the field show “7:30 PM” automatically. Eventually I would like to include an option for military time format, but that is not widely used at the moment by my end users.
The times entered are down to the minute like “12:01 PM” and sometimes I’ll need to show durations between times including the seconds.

I’m a complete beginner, but I know that this functionally is key to the success the project so I want to make sure this is possible before going too far down the path. Any comments appreciated.

Thanks

Maury - the following 3 links will help you achieve this:

link text
link text
link text

If you need further help, do not hesitate to ask again here - the community are always very helpful :slight_smile:

User entered text strings can easily have text prepended / appended etc, which will change the user entered time into the format you require :slight_smile:

[quote=137215:@Maury Jensen]Hello all,

I am brand new to Xojo and my goal is to build a custom scheduling and budgeting app for mac, windows and perhaps the web. A key component of this is being able to have my users enter times on a schedule with as few keystrokes as possible. I don’t really want to use pull down menus for this. I want times to be entered into text fields that then automatically format the text to the desired format.

A lot of this work is currently being done in Excel, and there the user can enter “7:30 p” and the software automatically sets the field to “7:30 PM” Even better would be if the user could enter “730p” and have the field show “7:30 PM” automatically. Eventually I would like to include an option for military time format, but that is not widely used at the moment by my end users.
The times entered are down to the minute like “12:01 PM” and sometimes I’ll need to show durations between times including the seconds.

I’m a complete beginner, but I know that this functionally is key to the success the project so I want to make sure this is possible before going too far down the path. Any comments appreciated.
[/quote]

There is no built in function to get the entry and turn it automatically into a computer representation. But Xojo string manipulation is elaborate enough to let you write the program needed to do what you describe. Durations can then be calculated automatically for you.

This can definitely be accomplished as you describe it. The idea for entering a time without a colon and with a trailing a/p is interesting so I put together a quick example. It doesn’t include a lot of basic error checking for invalid times but it should give you an idea of how this is possible.
https://www.dropbox.com/s/3otm6zc6h5j2190/format%20of%20times.xojo_binary_project?dl=0
Good luck!

We take a similar approach with time entry. With no a/p designation, we assume a 7 - 7 window. 8 is 8:00am, 8p is 8:00pm, 330 is 3:30 pm, etc.

Thanks everyone! I can see this is possible mostly through looking at Jason’s example. Other ideas welcome still welcome. I’ve got a long way to go, but nice to see this should be possible.

Tim Hare,

Would you be wiling to share an example of how you do the times as you described? I’m trying to get my head wrapped around the best way to do this?

Sure.

Function getTime(s as string) as string
   dim hr, mn as integer
   dim ampm as string
   dim n as integer

   if right(s, 1) = "a" then
      ampm = "a"
      s = left(s, s.len-1)
   elseif right(s, 1) = "p" then
      ampm = "p"
      s = left(s, s.len-1)
   end

   if CountFields(s, ":") > 1 then
      hr = val(NthField(s, ":", 1)
      mn = val(NthField(s, ":", 2)
   else
      n = val(s)
      if n <= 12 then
         hr= n
      else
         hr = floor(n/100)
         mn = n - hr*100
      end
   end
   if ampm = "" then
      if hr < 7 then hr = hr + 12
      if hr < 12 then ampm = "a" else ampm = "p"
   end

   s = str(hr) + ":" + format(mn, "00") + ampm
   return s
end

Warning:

hours with am/pm is a US (only) thing. Other parts of the world use 24 Hours a day: 8:00 and 20:00.

[quote=137353:@Emile Schwarz]Warning:

hours with am/pm is a US (only) thing. Other parts of the world use 24 Hours a day: 8:00 and 20:00.[/quote]

That is what he calls military time.

Almost right Emile. The brits use it too - we’re not quite under US rule yet :wink:

If you think American style timing is confusing, then wait for the dates…! :slight_smile:

8/7/11 = it could be sort of anything…! Especially with “creative users!” :slight_smile:

Jakob,

I know. I am in a Yahoo Group where (almost UK People) use all kind of date format (presentation, not number representations 14xx for Muslims, 56xx for Jews and 2014 for the rest of the world…).

I recall a certain day: 04/04/04… it was a friend father’s birthday !

Well… you miss my point.

The date format known as “2004-04-04” can not be mistaken, no matter the religion, while as there are plenty of alternatives if users are creative!

In Sweden, forms are often informative:
“Please write the day of birth: YYYY-MM-DD”

[quote=137383:@Jakob Krabbe]Well… you miss my point.

The date format known as “2004-04-04” can not be mistaken, no matter the religion, while as there are plenty of alternatives if users are creative!

In Sweden, forms are often informative:
“Please write the day of birth: YYYY-MM-DD”[/quote]

The example of 4/4/4 is interesting. Which is what ? Is it Y/M/D, or D/M/Y, or M/D/Y ? There are limits to any free form data entry.

Although it is slower, a good date picker such as Mike Cotrone’s is the only way to avoid possible confusion.

[quote=137359:@Emile Schwarz]
I recall a certain day: 04/04/04… it was a friend father’s birthday ![/quote]

That may be April 04, 1904 or April 04, 2004 or any other such date. Keeping in view the “friend father’s birthday”, how is that possible unless…

2004-04-04 COULD be YYYY MM DD or YYYY DD MM (odd but possible)

January 1, 2001 can’t be mistaken - however its not very internationally savvy

A survey of Americans asked what day and month ‘911’ happened and less than 50% knew. Of course the for the ROTW it is ‘119’!

Also, never understood why the USA holiday is called ‘the fourth of July’ as it is in British format.