Wednesday, May 18, 2011

Convert time between timezones

What to do if we want convert time between two timezones?

For example, an event occured at 15-00 by Moscow time(UTC+4). By that time, in Omsk(UTC+7) there is 18-00, three hours "more". We want to show time of event using local Omsk time.

How to do that in C++?

Fill tmDateExternal structure of type tm, with source event time(15-00). Save timezone shift of Moscow to in nSrcTZ, it is obviously 4.
__time64_t t64date = _mkgmtime64(&tmDateExternal) - nSrcTZ*60*60;
tm tmDateLocal;
_localtime64_s( &tmDateLocal, &t64date );

Now you have local Omsk time for that event in tmDateLocal structure.

Wednesday, December 8, 2010

Android: put ListView in a ScrollView

When I need to use ListView with other controls on the same screen, and it doesn't fit the screen vertically, I wish to get ScrollView over all controls, to scroll entire screen. But, that's the point when "shit happens".

Android core developers say you "must not put ListView inside ScrollView", because of many reasons, one of them - ListView has it's own scroll.

When you try just do it, ListView collapses, and you wish it not to be collapsed at all.

To accomplish that, I use a "hack", measuring and setting the height directly:

Sunday, May 30, 2010

Link in module title: Jumi + Articles Anywhere

How to set link in Joomla module title?
For example, let's show an article in module, with link to this article in module title.

1. Install Jumi, if you haven't done that already - it's incredibly useful component.

2. Install Articles Anywhere, plugin that displays article in any content.

3. Create Jumi module, publish it to position you choose, set any title, select option "Show title: Yes".

4. In "Code" field (on the right of module properties), write this code, with article_id changed to id of your article:

<?php $module->title="{article article_id}<a href=\"{url}\">{title}</a>{/article}"; ?>
{article article_id}{text}{/article}

Done!

First row will set module title to {article article_id}<a href="{url}">{title}</a>{/article}, and second will set module body.

Articles Anywhere plugin will parse tags in braces before display, changing it to corresponding html-code.

Why I Blog

For a number of times, I've encountered problems, with solutions not available anywhere on the net, and saw more inquiries about the same problem, unanswered. So I started my blog, to publish solutions I've found. This blog is also available on Russian, specially for my countrymates.

If you have something to say, please, leave a comment, I'll really appreciate it.