Why Cookies will not be stored if setting Timeout = 30 days in GWT? - gwt

This is very weird. Ok, the below code works fine
public void setCookie(String cookiesName, String cookiesValue){
final int COOKIE_TIMEOUT = 1000 * 60 * 60 * 24;//1 days
Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT);
Cookies.setCookie(cookiesName, cookiesValue, expires);
}
//then
setCookie("currentLang","de");
Collection<String> cookies = Cookies.getCookieNames();
for(String cookie : cookies){
if("currentLang".equals(cookie)){
System.out.println("got currentlang");
}
}
If i run the above code then I can see output: "got currentlang"
However, if I set timeout=30 days final int COOKIE_TIMEOUT = 1000 * 60 * 60 * 24 * 30;//30 days, then nothing got printed out, so "currentLang" has not even been stored if we set 30 days?
Why is that? does Gwt prevent that to happen?

You're using integer arithmetic for a sum that overflows beyond the maximum positive value for an integer. So 1000*60*60*24*30 is negative.
You could try 1000L*60*60*24*30

Related

Convert text column into time format column and calculate the sum

I have a one time column in format 00:01:30 (HH:MM:SS). This column is a text format column.
this text column format convert to a time format column and create a new measure for the total time sum.
You can easily convert your Text column into Time using
Time = TIMEVALUE('Table'[Text])
But the problem is that the Time format doesn't support more than 24 hours, so your SUM will potentially lead to an overflow. Here's a workaround:
Create a calculated "Seconds" Column
Seconds =
VAR Time =
TIMEVALUE('Table'[Text])
RETURN
HOUR(Time) * 3600 + MINUTE(Time) * 60 + SECOND(Time)
Aggregate the Seconds with this Measure and convert back to a "Duration-like" format:
Total Duration =
VAR total_seconds =
SUM('Table'[Seconds])
VAR days =
QUOTIENT(total_seconds, 24 * 60 *60)
VAR rest1 =
MOD(total_seconds, 24 * 60 * 60)
VAR hours =
QUOTIENT(rest1, 60 * 60)
VAR rest2 =
MOD(total_seconds, 60 * 60)
VAR minutes =
QUOTIENT(rest2, 60)
VAR seconds =
MOD(rest2, 60)
RETURN
days & "." & FORMAT(hours, "0#") & ":" & FORMAT(minutes, "0#") & ":" & FORMAT(seconds, "0#")

Firestore security rules for birthdate

I would like to have a Firestore security rule for bithdate field in my users collections where user age should be >=18 and <=80. I tried the following rule but I know it is not going to work especially for ages that are close to 18 or 80. Any idea how to make this work.
let now = request.time;
let thisYear = now.year();
let thisMonth = now.month();
let thisDay = now.day();
request.resource.data.birthdate >= timestamp.date(thisYear-80,thisMonth,thisDay) &&
request.resource.data.birthdate <= timestamp.date(thisYear-18,thisMonth,thisDay)
You can achieve the same result by comparing it with the request time but in seconds. here’s one example on how this will work:
function isAbove18(date) {
return date.seconds <= request.time.seconds - 18 * 365.25 * 24 * 60 * 60; //considering leap year with 0.25 🙃
}
function isBelow80(date) {
return date.seconds >= request.time.seconds - 80 * 365.25 * 24 * 60 * 60;
}
allow read, write: if isAbove18(resource.data.birthdate) && isBelow80(resource.data.birthdate);
For more about this you can go through this docs which takes some different approaches.

Compress date to unique alphanumeric characters

If I have a date YYMMDDHHmmss such as 190525234530 how do I work out the smallest number of characters to represent this using 0-9a-z (36 characters)?
I believe there are 3,153,600,000 combinations (100 years * 365 days * 24 hours * 60 minutes * 60 seconds) which would fit into 32 bits. Does this mean I could represent these dates using 4 characters?
I am a bit lost as to how to do the conversion so if anyone could show me the maths that would be greatly appreciated.
I ended up doing this in JavaScript, I decided I wanted to compress to 6 characters so I created my own time which generates unique ID's for up to 68 years from 01/01/2019 which worked for me.
function getId() {
//var newTime = parseInt(moment().format("X")) - 1546300800;//seconds since 01/01/2019
var newTime = Math.floor((new Date()).getTime() / 1000) - 1546300800;//seconds since 01/01/2019
var char = "0123456789abcdefghijklmnopqrstuvwxyz";//base 36
return char[Math.floor(newTime / 36**5)]+
char[Math.floor(newTime%36**5 / 36**4)]+
char[Math.floor(newTime%36**4 / 36**3)]+
char[Math.floor(newTime%36**3 / 36**2)]+
char[Math.floor(newTime%36**2 / 36)]+
char[Math.floor(newTime%36)];
}
console.log(getId());
Thanks to #user956584 this can be be changed to:
function getId() {
//var newTime = parseInt(moment().format("X")) - 1546300800;//seconds since 01/01/2019
var newTime = Math.floor((new Date()).getTime() / 1000) - 1546300800;//seconds since 01/01/2019
return newTime.toString(36);
}
console.log(getId());

Difference between two date time stamp in Intersystems Cache

I would like to find out the number of hours and minutes between two date time stamp.
if for example
sDateTime = 2016-01-01 01:00
eDateTime = 2016-01-03 02:30
I would like it to output it as 49:30 (49hours and 30minutes)
I am unable to figure a method to work this out.
what I have so far:
Set oMNOF=##class(MNOF.MNOF).%OpenId(Id)
Set zstartDt=oMNOF.sDateTime
Set startDt=$PIECE(zstartDt,",",1)
Set startTime=$PIECE(zstartDt,",",2)
Set zendDt=oMNOF.eDateTime
Set endDt=$PIECE(zendDt,",",1)
Set endTime=$PIECE(zendDt,",",2)
set dateDiff=((endDt - startDt)) //2 days
set timeDiff=(endTime - startTime) //outputs 5400 seconds
set d = (dateDiff * 24 * 60 * 60)
set h = ((timeDiff - d) / 60)
set m = timeDiff - (d) - (h * 60)
Thank you for the help.
Another option:
USER>set mm=$system.SQL.DATEDIFF("mi","2016-01-02 01:00","2016-01-03 02:30")
USER>write "hours=", mm \ 60
hours=25
USER>write "minutes=", mm # 60
minutes=30
Hi thanks to all for the help.
I managed to come up with the below, appreciate if someone can improve on this.
<script language="cache" method="MGetData" arguments="pStartDt:%String,pEndDt:%String,pTimeField:%String" returntype="%Library.String">
set val1="00"
//HOUR: check if length equals 1
if $LENGTH($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600))=1{
//add leading zero
set val1 ="0"_$SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)
}
else{
//get without leading zero
set val1 = $SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)
}
//MINUTES: check if length equals 1
if $LENGTH($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))=1{
//add leading zero
set val2 ="0"_($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))
}
else{
//get without leading zero
set val2 = ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/60) - ($SYSTEM.SQL.FLOOR($system.SQL.DATEDIFF("ss",pStartDt,pEndDt)/3600)*60))
}
//insert result data into the time field
Write "document.getElementById('"_pTimeField_"').value='"_val1_":"_val2_"';"
//Write "alert('"_val1_"^"_val2_"');"
QUIT 1

Comparing two Date values in ActionScript - possible to compare whole day values?

I need to be able to compare the number of whole days between two dates in ActionScript, is this possible?
I'd like to test if one date is 7 days or less after today, and if so is it one day or less (if it's before today this also counts).
The workaround I have in place is using the .time part of the date field:
// Get the diffence between the current date and the due date
var dateDiff:Date = new Date();
dateDiff.setTime (dueDate.time - currentDate.time);
if (dateDiff.time < ( 1 * 24 * 60 * 60 * 1000 ))
return "Date is within 1 day");
else if (dateDiff.time < ( 7 * 24 * 60 * 60 * 1000 ))
return "Date is within 7 days");
As I say - this is only a workaround, I'd like a permanent solution to allow me to check the number of whole days between 2 dates. Is this possible?
Thanks
var daysDifference:Number = Math.floor((dueDate.time-currentDate.time)/(1000*60*60*24));
if (daysDifference < 2)
return "Date is within 1 day";
else if (daysDifference < 8)
return "Date is within 7 days";