Java IsDateValid() functionality

I tried to check if the key of my product has expired or not using IsDateValid(). Even though the key hasn't expired, the function always returns false. Here is the code:Date dNow = new Date( );SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");ft.setTimeZone(TimeZone.getTimeZone("UTC"));TurboActivate.IsDateValid(ft.format(dNow), TurboActivate.TA_HAS_NOT_EXPIRED);

Please correct me if i am wrong regarding isDateValid() + suggest me a method to check wheather the key has expired or not. I would also like to know how the expiryDate check works if the user changes the computer date settings.

The "now" date will always be expired because by the time you call the IsDateValid() function the date will have passed.

Use a time in the future.

i am in thought that isDateValid() method checks the provided argument ie. date string with the expiryDate. is it correct?. FYI: for expiry there is still 7 days time for that key.Please correct me if i am wrong and plz explain me what that method does

, edited

Yes, that's what it does. But the date you're choosing has already expired. Does that make sense?

That's what the problem is . I still have the expiry time of 7 days, but isDateValid() with present time as argument returns me false. did i do anything wrong?

This code will always return false:

Date dNow = new Date( );SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");ft.setTimeZone(TimeZone.getTimeZone("UTC"));TurboActivate.IsDateValid(ft.format(dNow), TurboActivate.TA_HAS_NOT_EXPIRED); 

Is that the code you're using, or are you passing in a feature value to the IsDateValid() function?

I wanted to check if the key has expiried or not at the present moment.. So i would pass the present time. You said the that isDateValid() try to match the passed argument with expiry date. As present time is under the expiry date..it's a valid date. so i think it should return true.

I think you're getting confused. You're passing in a date to IsDateVali(). That's the only date that's checked. It doesn't check any other dates.

If you pass in a "Now" value then you call IsDateValid() it will always return false. Why? Because several seconds will have passed since you create the Date/Time string. That is, the "present" becomes the "past" very quickly.

Try creating a date in the future and you'll see IsDateValid() return true.

if i have to pass the future time, then how come i can check if the key is valid or not at present time. Is there is any other way to check if the present time falls under expiry date or not. Or can get the expiry date string?

I checked by passing the future time..as you said it returns true. But it returns true even the passed time is outside the expiry time. ie. suppose expiry time is 2012-09-20 00:01:00 and passed argument is 2012-09-21 00:01:00 isDateValid returns ture. which is not correct as passed date is over the expiry.if that is the case the how to check for expiry of the key?

I checked by passing the future time..as you said it returns true. But it returns true even the passed time is outside the expiry time. ie. suppose expiry time is 2012-09-20 00:01:00 and passed argument is 2012-09-21 00:01:00 isDateValid returns ture

This is correct behavior. I think you're still confused as to what IsDateValid() actually does. You use IsDateValid() to check if a feature value has expired.

Let's say you have an "update_expires" feature value. You set it to a month from now. So every time you check the "update_expires" value from now until a month from now IsDateValid will return true. Then From a month from now onward IsDateValid will return false.

Does that make sense?

Future value: IsDateValid() returns true.Past value: IsDateValid() return false.

Let's say you have an "update_expires" feature value.

I was discussing about the same.

You set it to a month from now. So every time you check the "update_expires" value from now until a month from now IsDateValid will return true.

I created a new key and it's expires exactly one month from now ie.expires on 19th October. So isDateValid() returns true if i pass it any future date that is under 19th Oct ie. say 1st Oct.

Then From a month from now onward IsDateValid will return false.

If the passed future date is 21st Oct, it should return false. But it isn't, it returns true. That's the problem is..

If the passed future date is 21st Oct, it should return false. But it isn't, it returns true. That's the problem is..

It's not October 22nd (that is, if I walk over to the calendar on my wall I'll see that today is currently September 19th, 2012). If today was October 22nd, then passing in October 21st to IsDateValid will return false.

I'm not sure how else I can explain this.

Can you please explain how you imagine IsDateValid() should work? Or what you imagine IsDateValid() checks?

"It's not October 22nd (that is, if I walk over to the calendar on my wall I'll see that today is currently September 19th, 2012). If today was October 22nd, then passing in October 21st to IsDateValid will return false."

That's the check for "isDateValid() returns true for future time and isDateValid() returns false for past time". But in the example, which I gave, "update_expires" value was 19th Oct. As passed value "21st Oct" is over the "update_expires" value, I expect it to return false, but it is'nt.

"Can you please explain how you imagine IsDateValid() should work? Or what you imagine IsDateValid() checks?"

Ok. I guess there is some differences between the way I look at isDateValid() method and the actual functionality of it. Here it is what i think of it: isDateValid() takes two parameters as arguments 1. is the "time string" 2. is the flag.It checks the "time string" with the feature value like "update_expires" and checks if the passed "time string" is within the bounds of "update_expires".From our discussion i came to know that if the passed "time string" is past date. the method returns false.I expect it to return false if the passed "time string" is over "update_expires".The purpose of my usage of this method is to check if the key used by my customer has expired or not wrt his system time.

It checks the "time string" with the feature value like "update_expires" and checks if the passed "time string" is within the bounds of "update_expires".

I don't know what you mean by "within the bounds" of a date, but it's obviously what you're not understanding. You can only ever be before a date or after a date. If you're before a date then IsDateValid() returns true. If you're after a date then IsDateValid() returns false. It's as simple as that.

"Let's say you have an "update_expires" feature value. You set it to a month from now. So every time you check the "update_expires" value from now until a month from now IsDateValid will return true. Then From a month from now onward IsDateValid will return false."

The above is the example given by you in our previous discussion. Let me give an example for my understanding of "Then From a month from now onward IsDateValid will return false."Let's say today's date is Oct 1st and I set "update_expires" to be Nov 1st. If I start my application on Nov 20th, then isDateValid() should return me false. But it's not the case. Does that make sense?

Can you please suggest me an api to check if key has expired or not?. Thank you for your time.

Let's say today's date is Oct 1st and I set "update_expires" to be Nov 1st. If I start my application on Nov 20th, then isDateValid() should return me false. But it's not the case. Does that make sense?

How are you testing that? Are you rolling your system clock forward? If so, that's why you're getting odd behavior. So, don't do that. If you want to test the behavior then pass in a date/time value that's before today.

Everything works here. If you're getting a bug then list the value you're testing that does not work as expected. Also give me the return code.

Wyatt,

Yes, we are rolling the date forward. We just integrated Lime into our project so we are trying to test it out fully. Does it do a server side check to validate? We can do a one day trial and let that day pass to perform a real IsDateValid() functionality test. Unless their is a better way...

ThanksLime LM Newb

Does it do a server side check to validate?

No, but we do various tests to detect fraud (rolling system dates forward and backward, etc.).

We can do a one day trial and let that day pass to perform a real IsDateValid() functionality test. Unless their is a better way...

Well, that's one way. Or just pass in an old value, and test your app. Then pass in a future value and test your app.

Api call from application:

               boolean activationStatus = lm.ValidateKey(serialKey.getText());              if(activationStatus)                     activationStatus = lm.GetActivateStatus();              if(!activationStatus){                     int trialPeriod = lm.GetTrailPeriod();                     JOptionPane.showMessageDialog(                                  null,                                  "Enter correct product serial");              }

validateKey(String s) implementation:

public static boolean ValidateKey(String key)       {              boolean existingKey;              boolean ekey;              try {                     existingKey = TurboActivate.IsProductKeyValid();                     try                     {                           ekey = TurboActivate.GetPKey().equals(key);                     }                     catch(Exception e)                     {                           ekey = false;                     }                     if (!ekey || !existingKey)                     {                           boolean z = TurboActivate.CheckAndSavePKey(key);                           if (!z)                                  return false;                           TurboActivate.Activate();                     }                     else{                         return TurboActivate.IsDateValid(getFutureOneHourTime(), TurboActivate.TA_HAS_NOT_EXPIRED);                           //return true;                     }              } catch (Exception e) {                     return false;              }              return true;       }       private static String getFutureOneHourTime(){           Date dNow = new Date( );           SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");           ft.setTimeZone(TimeZone.getTimeZone("UTC"));              String[] total       =  ft.format(dNow).split(" ");              String[] date        =  total[0].split("-");              String[] time        =  total[1].split(":", 2);              int hour             =  Integer.parseInt(time[0])+1;              int day              =  (Integer.parseInt(date[2]) + hour/24);              int daysOfMonth      =  getDaysOfMonth(Integer.parseInt(date[1]), Integer.parseInt(date[0]));              int month               =  Integer.parseInt(date[1])+ day/(daysOfMonth+1);              int year                  =  (Integer.parseInt(date[0]) + month/13);              month                   =  month!=12?month%12:month;              day                        =  day!=daysOfMonth?day%daysOfMonth:day;                           hour                      =  hour%24;              String sHour         =  hour/10<1? "0"+Integer.toString(hour):Integer.toString(hour);              String sDay          =  day/10<1? "0"+Integer.toString(day):Integer.toString(day);              String sMonth        =  month/10<1? "0"+Integer.toString(month):Integer.toString(month);              String sYear         =  Integer.toString(year);              return sYear+"-"+sMonth+"-"+sDay+" "+sHour+":"+time[1];       }       private static int getDaysOfMonth(int mon, int year){              if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)                     return 31;              else if(mon==4||mon==6||mon==9||mon==11)                     return 30;              else if(year%4!=0)                     return 28;              else                     return 29;       }

I wanted to add, this is a code sample from one of our developers to show how we are integrating via Java. In a nut shell, the license never expired. We set a few one day trials to let it run naturally and all failed. I am sure it has to do with the way we are implementing it. Any ideas?

Why are you deliberately getting a future value? It will always return true. See:

                         return TurboActivate.IsDateValid(getFutureOneHourTime(), TurboActivate.TA_HAS_NOT_EXPIRED);
The "now" date will always be expired because by the time you call the IsDateValid() function the date will have passed.Use a time in the future.

Ealier Sam asked me to pass the future value. That's why i was passing time of an hour future.

Why are you deliberately getting a future value? It will always return true.

It will return true for future value only if the key hasn't expired . But it's not the case if the key already expired.does it make sense?

I don't think you understand the function at all. I'm not sure how I can explain it in a way that hasn't already been explained several ways in this thread.

I think you're overthinking it. Just let IsDateValid() handle all the details. IsDateValid() validates a date you pass in. Use it for feature values. That's it. Don't pass in fabricated dates. Don't mess with your system time.

Just pass in Date/Time feature values.