I want to include a timeout duration, like "25 seconds" or "1 minute", in a user-facing message. Is there a way to do this in gwt?
From this resource, I know that I can do dates like this:
#DefaultMessage("Last update: {0,date,medium} {0,time,medium}")
String lastUpdate(Date timestamp);
but there doesn't seem to be anything like:
// hypothetical
#DefaultMessage("Requests time out after {0,duration}")
String timeout(Interval duration); // also Interval is a JodaTime concept...
Is there?
JodaTime still isn't really available for GWT (there are/were several projects, but unfortunately none ever really established itself). I hope someday we'll see JavaSE 8's new Date API in GWT!
Until then, I would use the following approach:
Storing the duration as a number of seconds (or milliseconds if required).
Creating one internationalized message for 0-59 seconds, one for 1-59 minutes, and one for 1-... hours.
Each of these messages can use Plural Forms.
Selecting the best message (seconds/minutes/hours) programmatically.
Related
Requirement: I need to monitor the Twilio account and subaccount usages in near real-time.
Any solution in java, php, python or even curl will do for me.
Twilio provides Usage Records API and allows some subresources which contains Today but that returns all data from the start of that day till the nearest current time. I am unable to find anything in the documents that would retrieve only usages of the last minute or last 10 minutes or even between two time constants. The Usage API accepts two dates but not time.
Hoping someone out there has a solution to offer.
I'm writing a toy logistics service. As a result, products will travel through lots of different timezones, and I'll need to query both the strict ordering of events, as well as what hour of day it is for products (for example, what happened when the sun was at its hottest, at 1200).
At the moment, I'm saving jodatime DateTimes and trying to deal with them exclusively, but I know time is mighty tricky, and I'm wondering if I need to do anything else to make sure it all works.
Given that you're recording events as they occur (rather than planning for future events), you probably don't need to worry about changes to time zone rules which occur in the future.
As such, it would be reasonable to store a timestamp (e.g. as UTC) and also the time zone ID for the location of the event. To make querying easier, you could also store the local time at the time of the event. Just be aware that as a toy is travelling through time zones, there could be multiple events at different instants in time, all of which occur at "midday" on the same day (but in different zones). You really need to think carefully about what queries you really want to perform on the local date/time values.
I am not familiar with jodatime but when I need to store the time I always enjoy using Epoch time because it is very easy to manipulate to get different formats. If you're interested in it here is a converter website that I find very helpful: http://www.epochconverter.com/
In soccer (most places, they call it football), the game time is shown as mm:ss, even if there are more than 59 minutes, so if at one hour 22 minutes, 32 seconds into the game, it would be displayed as 82:32.
I have the time as an android.text.format.Time, with hours, minutes and seconds set, which means that I can easily have it as a number of milliseconds since the epoch. Looking through the formatting options (like Time.format(String)), the format specifiers for minutes seems to always have the range [0, 59). Short of writing my own formatter (not hard, but I'm worried about localization), is there a format call that will do what I want here? Thanks.
My specific fears about localization are as follows:
Time separator (':' vs. '.' or some other thing--I don't know the separators that various locales use).
Order. I could imagine some cultures displaying 32:82 in the example from above.
Something even more horrible that I haven't thought of yet.
Obviously, 1 and 2 are solvable with a smart, localized format string with good comments. 3 scares me, but I may just be being paranoid.
I really think you'll be best either
a) not using any Time.format at all - just doing simple math to figure figure out the minutes and seconds and then displaying mm:ss, or
b) using localized format strings if you absolutely need them.
Your first two worries will not be a problem in almost all cases: using a colon to separate minutes and seconds is common across many cultures, as is displaying the minutes before the seconds. In fact, it's the ISO standard: http://en.wikipedia.org/wiki/ISO_8601
If you're really worried about it and want to do a little investigating, I would find videos of soccer matches being broadcast in different languages / locations. I just found one on YouTube in Chinese, and it's using mm:ss to display the time.
I have already a table with three time fields. One to register the hour when the user start working, when stop working and the difference. Now I want to add the day of the week(Mon-Sun) and the date. How can I properly do that, saying that then I will want to grab the hours that the user worked in the past 7 days, lets say.
I've read that timestamp give all the information but I don't know whether I can separate days from date?
**table name = date_time
date_time_id = auto increment
user_id = var
time_in = time
time_out = time
time_dif = time**
ps: I am using java(servlets) and mysql.
Thanks guys
when I start getting really silly with yime in MySql, I use unix time. MySql has built in functions for unix time conversion, too. FROM_UNIXTIME() is one of them. Here's url of a reference page I use.
I've been burned by MySql time (probably more by my own confusion) a few times, so I prefer unix time and then I can manually figure things out by factoring seconds into minutes *60 and hours *60*60 and days *24*60*60.
Change your column types to TIMESTAMP instead of TIME. A timestamp includes both a date and a time.
You should hav column datetime type So you can easily get days month week whatever required.
Here all functions listed you can use as desired with datetime field:
Date and Time Functions
Use org.joda Datetime java library. Its very easy and you can do all the calculations using timestamp.
Let's say I'm performing a SQL query from a Java program to get timestamps (stored as milliseconds) from a table of timestamps that occur within the last 10 days.
I can think of the following two ways to do this:
db.execSql("select * from timestamps where timestamp > (SELECT strftime('%s', 'now', '-10 days') * 1000)");
or
// First calculate in the number of milliseconds in Java
long t = System.currentTimeInMillis() - (10 * 86400000 /* millis in a day */);
db.execSql("select * from timestamps where timestamp > " + t);
Both get the job done and seem to be equivalent perf-wise when testing. Is one method preferred over the other? Does it matter? Is there an idiomatic way to do this?
How important is exactness on the boundaries? The time as seen by the server could be different than the time on the Java VM by several hours (e.g. timezones). I would generally go with the server-time based one, but my usual application would want to use the start of day and not NOW() so that the "bucket-boundaries" don't slide.
I generally prefer to use the second method: if you end up needing to change the number of days, or the date from which the ten-day window is calculated, it will probably be more straightforward, understandable and maintainable to handle that in Java.
Although I have no conclusive tests to prove this and this is just conjecture, I think I'd want to compute it in the software (via Java) and put the "bottleneck" there. Although it may be the same performance-wise, I wouldn't want the DB to be doing unnecessary work if it doesn't have to.
My guess is that you may have many clients running the same piece of software, but they're probably all querying the same database. Therefore, I side with the latter example.