function TimeLogFromDateTime(dataText) {
var giorno = new Date(dataText).getDate();
var mese = new Date(dataText).getMonth();
mese++;
var anno = new Date(dataText).getFullYear();
var temp = 0 + (giorno * Math.pow(2,5)) + (mese * Math.pow(2,10)) + (anno * Math.pow(2,14)) - ((1 * Math.pow(2,5)) + (1 * Math.pow(2,10)));
var result = temp * Math.pow(2,12);
return result;
}
function TimeLogToDateTime(Value) {
var result = new Date();
//window.alert(Value);
var Y = Math.round(Value / Math.pow(2,(6+6+5+5+4)) & 4095);
var M = 1+((Value) / Math.pow(2,(6+6+5+5))) & 15;
var D = 1+((Value) / Math.pow(2,(6+6+5))) & 31;
result.setFullYear(Y);
result.setMonth(M-1);
result.setDate(D);
result.setHours(0);
result.setMinutes(0);
result.setSeconds(0);
result.setMilliseconds(0);
if (Value & (1 * Math.pow(2,(6+6+5))-1) != 0) {
var HH = ((Value) / Math.pow(2,(6+6))) & 31;
var MM = ((Value) / Math.pow(2,6)) & 63;
var SS = (Value) & 63;
result.setHours(HH);
result.setMinutes(MM);
result.setSeconds(SS);
result.setMilliseconds(0);
}
return result;
}
var temp = 0 + (day * Math.pow(2,5)) + (month * Math.pow(2,10)) + (year * Math.pow(2,14)) - ((1 * Math.pow(2,5)) + (1 * Math.pow(2,10)));
var timeLog = temp * Math.pow(2,12);
this javascript code seems to work!
]]>var timeLog = 0 + (day * 5) + (month * 10) + (year * 14) - ((1 * 5) + (1 * 10));
timeLog = (timeLog * 12);
like this?
]]>var timeLog = 0 + (day << 5) + (month << 10) + (year << 14) - ((1 << 5) + (1 << 10));
timeLog = (timeLog << 12);
NB i need date only
where i mistake?
// bits: S=0..5 M=6..11 H=12..16 D=17..21 M=22..25 Y=26..38
// size: S=6 M=6 H=5 D=5 M=4 Y=12
// i.e. S<64 M<64 H<32 D<32 M<16 Y<4096: power of 2 -> use fast shl/shr
procedure TTimeLogBits.From(Y, M, D, HH, MM, SS: cardinal);
begin
inc(HH,D shl 5+M shl 10+Y shl 14-(1 shl 5+1 shl 10));
Value := SS+MM shl 6+Int64(HH) shl 12;
end;
function TTimeLogBits.Year: Integer;
begin
result := (Value shr (6+6+5+5+4)) and 4095;
end;
function TTimeLogBits.Month: Integer;
begin
result := 1+(Int64Rec(Value).Lo shr (6+6+5+5)) and 15;
end;
function TTimeLogBits.Day: Integer;
begin
result := 1+(Int64Rec(Value).Lo shr (6+6+5)) and 31;
end;
function TTimeLogBits.Hour: Integer;
begin
result := (Int64Rec(Value).Lo shr (6+6)) and 31;
end;
function TTimeLogBits.Minute: Integer;
begin
result := (Int64Rec(Value).Lo shr 6) and 63;
end;
function TTimeLogBits.Second: Integer;
begin
result := Int64Rec(Value).Lo and 63;
end;