1

I'm downloading an image file from a server, everyday after 9am in morning as per my Timezone. I also wish to display the file next day sharp at 9am

So I'll update that image file before 9am as per my Timezone, that'll make sure I get updated image file everyday. And all users get enough time to download that same image file i.e 23hrs and 45 minutes max. * 15 mins are considered for updation purpose

Now the app works fine if users are from my Timezone, but it won't work if user are ahead then my Timezone. Chances are more of getting same image file twice.

Also if I choose to update file as per Timezone where 9am occurs first then users in other part won't get 23hrs and 45 mintues time to download.

I'd like to know any other solution rather than having seperate server for each timezone, as it is also difficult to implement in app too.

UPDATE I think there is no way to provide a window of 23hrs and 45 mins max and displaying image next day at 9am. Both things can't be achieved in multiple timezones.

I'm using an image with hotlink i.e direct download link with same address.

kevz
  • 2,727
  • 14
  • 39
  • Does your (server’s) time zone have summer time (daylight saving time)? – Ole V.V. Dec 04 '17 at 13:21
  • @Ole V.V:I don't know wt exactly u r saying but file updation doesn't have to do with server time. As I am the one updating it as per my Timezone. – kevz Dec 04 '17 at 13:24
  • When you want to display the image next day at 9 AM, is that 9 AM in the server time zone or the user’s time zone? Note that in rare instances, 9 AM next day in the user’s time zone may still fall before 9 AM in your server’s time zone — time zones may be more than 24 hours apart. – Ole V.V. Dec 04 '17 at 13:25
  • Its as per user time zone. – kevz Dec 04 '17 at 13:26
  • One option is that the client knows in which time zone the image is available from 9 AM and converts that time to its own time zone. How to do that has been asked and answered many times, for example [Timezone conversion](https://stackoverflow.com/questions/6567923/timezone-conversion). Make your own search to find more. – Ole V.V. Dec 04 '17 at 13:44
  • I want to make sure that every user gets 23 hrs and 45 min max for downloading file, I don't understand how that can be done by time conversion as per timezone. – kevz Dec 04 '17 at 14:27
  • What do you mean by updating the image? What does the image contain? Is it something like a graph of data over a specific time period? – Matt Johnson-Pint Dec 04 '17 at 17:41
  • Please edit your Question to simplify the problem description. Less discussion. Just list the steps in chronological order that should happen. – Basil Bourque Dec 05 '17 at 17:50

2 Answers2

1

As I understand your requirements

  • Image upload happens every day between 8:45 and 9 AM in the uploader’s (your) time zone. Download is possible at all other times.
  • Each client should display the image from the previous day every day at 9 AM in the client’s time zone.
  • The client should be allowed a window of 23 h 45 min for downloading the image.

I also understand that it works nicely with clients in your own time zone.

Let’s look at the example from your comment to another answer: Upload happens from Asia/Kolkata time zone (India), and there is a client in Asia/Tokyo time zone (Japan). When the upload is finished at 9 in India, the time is already 12:30 in Japan. There are websites that will make such time zone conversions for you, for example Time Zone Converter – Time Difference Calculator. At 12:30 in Japan there are only 20 h 30 min left until the image should be displayed at 9 the next morning. So we cannot fulfil the requirements.

Let’s for a moment imagine that you settle with a 20 h 30 window (which you may not want to). For the client to find out when and how long that window is, it just needs to know the uploader’s time zone. It then converts 9:00 Asia/Kolkata to 12:30 Asia/Tokyo to discover that the window opens at 12:30. How to do the conversion in the client program, you can find that in other questions and answers, for example Timezone conversion.

If the client in Tokyo needs a 23 h 45 window, you will need to upload the image earlier. More precisely, it needs to be uploaded no later than 9:15 Japanese time. Again, convert this time to your own time zone to find out when that is.

We’re not done yet. While Japanese time (UTC+9) is ahead of Indian time, some time zones are even further ahead. According to Time Zone Abbreviations – Worldwide List some time zones are at UTC+14, either all year or in summer. And the list isn’t static. To prepare for future changes, you may want to add another couple of hours. Zone offsets in java.time go to UTC+18.

If you upload your image before 9:15 at, say, UTC+16, you are creating a challenge for clients in your own time zone and other time zones that are not that far ahead. Clients may be able to cope with the challenge if they know when the upload happens. It just means that very often they will have to save more pictures for the days to come, and they will need to convert the upload time to their own time zone. A more practical way to handle the latter is probably to announce and handle upload time in UTC, as Abdul Waheed said in another answer.

ThreeTenABP

For your time zone conversions I recommend JSR-310, the modern Java date and time API also known as java.time. This is not built-in on most Android devices yet (it will come), so you need the ThreeTenABP, the backport of JSR-310 to Android. There is a thorough explanation in this question: How to use ThreeTenABP in Android Project. Then you may for instance code your time zone conversion using this answer.

To learn more about the modern API, visit the Oracle tutorial or find other resources on the net.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
-1

You can do this via using UTC time. You need to get current UTC and then convert the time to device current time zone then you will be able to get what you want. Hope that helps.

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • does that mean I have to download file by converting 9am to local device time and download image file? – kevz Dec 04 '17 at 12:34
  • You need to get current UTC time(free webservice is already available that returns UTC time) and then convert that utc to device current time zone and now check your condition at what time you want your file to be downloaded. – Abdul Waheed Dec 04 '17 at 12:45
  • I have modified the question, I need to show that downloaded image file sharp at 9 am on every device. – kevz Dec 04 '17 at 12:48
  • does that mean I can't have 23hrs and 45 mins for every user in multiple timezone for downloading that file? – kevz Dec 04 '17 at 13:06
  • No, it is not like that utc is a standard time and if you convert that according to time zone you will definitely get the thing you want – Abdul Waheed Dec 04 '17 at 13:46
  • I don't understand how can a user from Japan get (without reducing 23hrs and 45 mins) updated image if I am updating it b4 9 am from India? – kevz Dec 04 '17 at 14:24
  • That user can’t. At 9 AM in India it’s already 12:30 in Tokyo, Japan. Since the device is required to show the image next morning at 9 Tokyo time, there is only a 20 hour 30 minutes window for downloading it. – Ole V.V. Dec 04 '17 at 17:40