Friday, April 15, 2011

Trying REBOL

REBOL was the language I wanted to explore. Today I thought of writing a timezone converter application using REBOL.

The application should be able to convert time from Indian timezone to Munich and Boston timezone. This conversion is related to my current project.

With this weird requirement, I decided to use the most weird way to convert time. I decided to use the timezone converter to do the conversion. As a result, the application has to make an HTTP GET call to this link and parse the resulting web page to find the converted time.

Summarizing the Approach:
  1. Write a REBOL UI application that takes the Indian time as input
  2. On click of Convert, makes an HTTP call to the website with input given by the user.
  3. Parse the resulting web page and find the converted time.
  4. Show the converted time on the UI !!

Here is the REBOL code for the application.
This is a REBOL code for timezone convertor

Title: "Timezone Convertor IN to BOS & MUN"
Author: "Srikanth Seshadri"

t-time: to-string now/time

time-get: func [inp-time tz] [
page: reform [
tzurl: to-url page
tz-text: load/markup tzurl
zone-found: false tg-time: now
foreach item tz-text [
if all [string? item zone-found ] [ tg-time: item break]
if all [string? item any[ find item "(U.S.A" find item "(Germ"] ] [zone-found: true]

gui: layout [
backdrop effect [gradient 0x1 white]
h3 "Timezone Converter IN -> BOS & MUN" black return
lab "Indian Time"
t-time: field t-time 60x24 return
button "Convert Time" [
inp-time: (to-time t-time/text)
if inp-time
boslbl/text: reform ["Time in Boston: " time-get inp-time 43]
munlbl/text: reform ["Time in Munich: " time-get inp-time 83]
show boslbl
show munlbl
] keycode [#"^m"] return
boslbl: h4 "[---------------------------------------------------------------------]" return
munlbl: h4 "[---------------------------------------------------------------------]" return
view center-face gui

and the output

This is most strange way to do timezone conversion, but the learnings and development was fun; all the effort was worth it!