formatting strings: CID and localTime

Support zone
Post Reply
rybshik
Posts: 33
Joined: Mon Jun 08, 2009 2:20 am

formatting strings: CID and localTime

Post by rybshik » Wed Feb 04, 2015 7:42 am

In my dialplan, for each incoming call, caller number (CID) and the time of the call are sent out by email:

Code: Select all

localTime = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes())

caller = req.Header.From.FromURI.User

sys.Email("user@gmail.com", "Incoming call", "from #{caller},  #{localTime}") 
So the body of the email message looks like this:
"from 4161234567, 2/4/2015 2:15:29 AM"
or possibly has leading prefix 1 like this
"from 14161234567, 2/4/2015 2:15:29 AM"

I want to format CID by removing leading prefix 1 (if any) and inserting dashes, and also want to remove date and seconds and keep just hours and minutes, so the body of the email message will look like this:
"from 416-123-4567, 2:15 AM"
Thanks

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: formatting strings: CID and localTime

Post by Aaron » Wed Feb 04, 2015 10:37 am

This should get you pretty close.

Code: Select all

localTime = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes()).ToString("hh:mm tt")

caller = req.Header.From.FromURI.User.Trim('1').to_s.insert(3, '-').insert(7, '-')

sys.Email("user@gmail.com", "Incoming call", "from #{caller},  #{localTime}")

rybshik
Posts: 33
Joined: Mon Jun 08, 2009 2:20 am

Re: formatting strings: CID and localTime

Post by rybshik » Thu Feb 05, 2015 12:52 am

Aaron wrote:localTime = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes()).ToString("hh:mm tt")
Thanks.
Is there an option to display time in the military (24h) format?
SOLVED:

Code: Select all

localTime = System::DateTime.UtcNow.AddMinutes(sys.GetTimezoneOffsetMinutes()).ToString("HH:mm")

Post Reply