I am using TimeZone class to get the time zone in SHORT format like "PST", "EST" etc. using TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT, Locale.getDefault())
For some devices this piece of code is returning "PST" etc but some of the devices its returning "GMT+007" value. Anybody has an idea what can be the change I make to make it consistent to "PST" format.
The short name is a part of the time zone database. It seems that some devices are shipping time zone databases that doesn't include this information, or whose libraries ignore it.
To make this consistent I would include a mapping that maps from the long names to the short names. But then you would have to maintain that yourself, and you also need to get the long name (like "US/Hawaii") for each timezone, I don't know if that is possible for you, it depends on the use case.
Please also be aware that the short time zone names are ambiguous, there are many time zones called EST for example.
Related
I've an app that uses the LocationManager in Android and i'm tryng to get the current time provided by gps in millis.
I noticed in my database a row with a wrong timestamp.
There's others that are always corrected, for example:
1477050084629: Correct time provided
6406148: Incorrect time provided
The incorrect time is provided by using a device Samsung SM-J105B (Galaxy J1 Mini Dual Chip).
I didn't find topics related a problem like this, only problems when the time is different by hours or days.
In my case the timestamp return a number of small quantity of digits.
I think the problem would be generated by device, see this topic:
https://support.strava.com/hc/en-us/articles/216515918-My-Activity-has-the-wrong-date-
I'm assuming a bigint column. Ask yourself is one bit not set on a binary number? Look at the code that uses that column then look specifically how the value is passed in code is it serialized when it's passed to your code? Check if the value is converted to and from human readable timestamps.
I have a set of strings like "Friday 8:00am till 6:00pm", how do I localize this string to different languages.
I've tried to use 2 Calendars and SimpleDateFormat, but it doesn't support several values.
Use DateUtils.formatDateRange(...) to format time spans.
Formats a date or a time range according to the local conventions.
Although this will not allow you to localize parts of it yourself, it will provide a consistent user experience on the device and is properly localized. You can modify what and how it is displayed by providing various flags.
I'm a word puzzle junky in my spare time, so I've spent a LOT of other spare time working on a helper program that allows wildcards in search patterns. It works great. On my Dell Laptop (i5, 8GB RAM) the search of a 140,000-word "dictionary" for wildcard matches for words has an almost imperceptible and definitely acceptable delay that occurs only if tens of thousands of words are returned. Java rules. So does its implementation of regex and match().
I was hoping to port it to Android. I worked all day getting a more-or-less equivalent app to compile. No chance with given code architecture.
The problem is that leading wildcard characters can (must) be allowed. E.g., ???ENE returns 15 matches--from achENE to xylENE and *RAT returns 22 matches--from aristocRAT through `zikuRAT--i.e., all 140,000 words must (?) be searched, which is going to take aaaaaaaaawhiiiiiiiiile on most (all?) Android devices. (Each took less than a second on my laptop.) (It takes my PC 3 seconds to return all 140,000 words and a little longer to eyeball them all.)
Since some word puzzles allow variable numbers of letters in words, disallowing leading wildcards cuts the heart out of the app for such puzzles. But if the search pattern had to start with a letter it would be easy enough to then do a binary search (or something quicker). (And it still might be unacceptably slow.)
Anyway, I was wondering if anybody might know some algorithm or can think of some approach that might be applied to speed up searches with leading wildcard characters.
I believe that the optimized version of what you are trying to do is widely known as the Unix/Linux utility "grep", which, if I remember correctly, uses the Boyer-Moore search algorithm.
Under the covers, Java's Pattern class uses Boyer-Moore. And it supports regex, so if you can write something to turn your wildcard search patterns into regular expressions, you can use Pattern.
There's an interesting Java implementation of grep at http://www.java2s.com/Code/Java/Regular-Expressions/AnotherGrep.htm
It uses memory-mapped files. I'm guessing that you won't be able to fit your entire word list into memory, but you could split it up into a bunch of smaller files - the implementation above memory-maps one file at a time. You'd have to do some testing to find the optimal size of a file.
I just Googled and found having a second list reverse alphabetized might be a way to then have a leading wildcard become trailing, opening door to binary search for pattern start. Interesting. But *a???ene* is also a legal search pattern in the program. What then? (Yeah. How often would you need such a search.)
I just found this about Apache Lucene:
Leading wildcards (e.g. *ook) are not supported by the QueryParser by default. As of Lucene 2.1, they can be enabled by calling QueryParser.setAllowLeadingWildcard( true ). Note that this can be an expensive operation: it requires scanning the list of tokens in the index in its entirety to look for those that match the pattern.
So,
i'm using greendDao library and i want to store in SQL a date, but always is a timestamp date.
I do not want that!
Is possible to change that configuration?
Looking at the greedDao source i found that the date property is set by Integer type.
As a need a fast solution, i'll not add Date property, but string property and save the Date formated.
Maybe later i can fork greenDao and do the changes.
I did some adjustments to greendao. These include a method setDateFormat(String format). This method actually only applies for export to csv which is also among the adjustments I made. I will also include some lines to automatically truncate the date according to the format given.
I plan to make my changes available as plugins or extensions to greendao via contribution. Unfortunately I don't have time right now and so this project will have to wait.
Until then I suggest using date-properties and writing additional getters and setters in the KEEP-SECTION. This way you won't lose the possibility to sort this columns and you will probably be able to use the database in future (when there are possibilities to limit the value to date or time), since you don't have to change the column-type.
Using Strings is of course also a valid approach.
This question is not specific to Android but I have included the tag.
I need to be able to store phone numbers in some sort of standard form (ideally a string) where equality can be tested/evaluated quickly (hence a string would be ideal)
I found some answers already, the best ones pointed to http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html (I'm fine with using a library to do it for me)
BUT this isn't really good enough, I've tried a variety of format numbers, learnt about the Editable factory to use some of the static methods in that class, but they don't seem to return the form I was expecting.
I was expecting something like a phone-number-hash, that two inputs representing the same number would yield the same in this "standard form" and that one could dial this standard form and be fine. I thought that all the various +s and whatnot would be short-hands for this standard form.
I'm not sure if such a thing exists now.
I understand that some things mean "current area" (or country) which is why land-lines can ommit area codes, I expected a function that would return the format for the current location (but this doesn't apply to mobiles, if it were a land line to prepend the area code for example, this would be (closer) to the "standard form" I keep assuming exists)
I am pretty sure that some full-form for phone numbers exists, thinking about how the telephone system works (which I infer I admit) there ought to be a form that identifies a number uniquely across the whole planet, and when this is not the case (such as local calls from land-lines without area codes) it is an optimisation.
So I have two questions:
How can I "expand" a phone number to a unique string for that number, such that any alternate forms of writing that number (with spaces, an 0 or +44....) "expand" to this unique number?
Are there any ISO(/IEC?) (what's the O stand for?) standard documents with drafts open to the public? I've read the Wikipedia page (ages ago, I've spent so many hours wiki-browsing, and opened hundreds of tabs) but it covers history, or some information on formatting), I'd like to know more about the thing I've taken for granted now for some 8 years or so.
Additionally, why is Windows Phone 8 a tag? To make the 12 proud Lumina owners not feel left out? (It was suggested as a tag!)
Addendum
Unfortunately Any API in android to normalize phone number there are no solutions there (this includes libphonenumber) and my quest to find out has lead to some interesting reads:
http://en.wikipedia.org/wiki/Panel_switch
http://en.wikipedia.org/wiki/Nonblocking_minimal_spanning_switch
http://en.wikipedia.org/wiki/Telephone_exchange
and I still cannot conclude there isn't some "full form" for numbers.
I dare not create a solution that simply swaps +44 for an 0 and such.
After reading your question, I was reminded of Google's library called libphonenumber. Its Google's common library for parsing, formatting, storing and validating international phone numbers. It does the following things ( some of which seem what you might be able to use):
Parsing/formatting/validating phone numbers for all countries/regions
of the world.
getNumberType - gets the type of the number based on
the number itself; able to distinguish Fixed-line, Mobile, Toll-free,
Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever
feasible).
isNumberMatch - gets a confidence level on whether two
numbers could be the same.
isPossibleNumber - quickly guessing whether a number is a possible
phonenumber by using only the length information, much faster than a
full validation.
isValidNumber - full validation of a phone number
for a region using length and prefix information.
AsYouTypeFormatter - formats phone numbers on-the-fly when users enter each digit.
PhoneNumberOfflineGeocoder - provides geographical information related to a phone number.
As far as international format of phone number is concerned, E.164 format is an recommended by International Telecommunication Union. It defines a numbering plan for the world-wide public switched telephone network and is a general format for international telephone numbers ( usually stats with + followed by country code, Area code and the number).
Using the above library, validity of all the phone numbers can be checked if you mention the international code along with the phone number ( example 1 for US & Canada). If you don't have the code but you know the country's name for which you want to check the number, then also you can validate. You can also convert all the valid numbers of 1 standard E.164 format using this library. You can also 'expand' a number in Local National format of that particular country. You can save it as String as well. Although it does use PhoneNumberUtils that you mentioned in your question.
I am not sure if this is what you are looking for but I hope this information helps you.