- 473 views
- 0 comments
I can’t say that this code actually returns an accurate value but I was impressed that I could just copy it out of an app I wrote back in July (an app that served as the subject of this blog’s first post, incidentally) and slam it into one of the new ZC function constructs to see it “just work” by returning the string value as one would expect.
The idea is to take whatever zoho.currenttime() is reporting and express it as UTC but I suspect the ZC team has since added features native to the platform that obviate the need for it:
string calculations.CalculateUTCTime()
{
// see http://answers.google.com/answers/threadview?id=560486
grab_time=zoho.currenttime;
epoch_seconds=((grab_time.toLong() / 1000)).toLong();
days=(epoch_seconds / 86400);
days_int=(days.toString().getPrefix(".")).toLong();
day_fraction=(days - days_int);
secs_left_over=(day_fraction * 86400);
hrs=(secs_left_over / 3600);
hrs_int=(hrs.toString().getPrefix(".")).toLong();
hrs_fraction=(hrs - hrs_int);
hours=hrs_int;
secs_left_over=((hrs_fraction * 3600)).toLong();
mins=(secs_left_over / 60);
mins_int=(((mins)).toString().getPrefix(".")).toLong();
mins_fraction=(mins - mins_int);
minutes="";
if((((mins_int).toString()).length() < 2))
{
minutes="0" + (mins_int);
}
else
{
minutes=(mins_int).toString();
}
secs_left_over=((mins_fraction * 60)).toLong();
secs_int=secs_left_over.toLong();
seconds="";
if(((secs_int.toString()).length() < 2))
{
seconds="0" + secs_int;
}
else
{
seconds=secs_int.toString();
}
// see: http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7323
a=(days_int + 2472632);
b=(4 * a + 3);
b=((b / 146097)).toLong();
c=(((0 - b) * 146097)).toLong();
c=((c / 4)).toLong();
c=(c + a);
d=(4 * c + 3);
d=((d / 1461)).toLong();
e=((0 - 1461) * d);
e=((e / 4)).toLong();
e=(e + c);
m=(5 * e + 2);
m=((m / 153)).toLong();
dd=(153 * m + 2);
dd=((dd / 5)).toLong();
day=(0 - dd + e + 1);
mm=(((0 - m) / 10)).toLong();
mm=(mm * 12);
month=(mm + m + 3);
year=((b * 100 + d - 4800 + m / 10)).toLong();
month_str="";
if((month == 1))
{
month_str="Jan";
}
else if((month == 2))
{
month_str="Feb";
}
else if((month == 3))
{
month_str="Mar";
}
else if((month == 4))
{
month_str="Apr";
}
else if((month == 5))
{
month_str="May";
}
else if((month == 6))
{
month_str="Jun";
}
else if((month == 7))
{
month_str="Jul";
}
else if((month == 8))
{
month_str="Aug";
}
else if((month == 9))
{
month_str="Sep";
}
else if((month == 10))
{
month_str="Oct";
}
else if((month == 11))
{
month_str="Nov";
}
else if((month == 12))
{
month_str="Dec";
}
ts=((day + "-" + month_str + "-" + year + " " + hours + ":" + minutes) + ":") + seconds;
return ts;
}



Add A Comment