xpages Date Compare - datetime

Hi i want to write Style ssjs for plan view. Set on column date variable "01.06.2007" and if document start date + duration contains 01.06.2007 result is background color change.
DateConverter.stringToDate = Java.util.date Tommy Valand code. (http://dontpanic82.blogspot.com.tr/2010/04/xpages-code-snippet-for-datestring.html)
//-------------------------------------------------
col = 0;
var zeroDate = DateConverter.stringToDate( '01.06.2007', 'dd.MM.yyyy' )
colDate = #Adjust(zeroDate, 0, 0, col, 0, 0, 0);
duration = parseInt(rowData.getColumnValue("Duration"));
startDate = rowData.getColumnValue("Start Date");
endDate = #Adjust(startDate, 0, 0, (duration-1), 0, 0, 0);
if(startDate == colDate){
"startColor"}else if(startDate < coldate && (colDate < endDate)){
"perColor"}else{
"bgColor"}`

You cannot compare date values with < or > AFAIK. Transform your NotesDateTime stuff into Java date objects and use the before() and after() methods.
Like
var startDate:NotesDateTime = ... ;
if(startDate.toJavaDate().before(colDate.toJavaDate()) && ... ){
...
}

Related

Lua timer script producing all-numeric value instead of proper time

My timer script writes this into the file when it saves the value.
Example Time in file: 1638185640
Example of time displayed in game:
name = "Timer"
description = "Just a normal Timer."
positionX = 0
positionY = 0
sizeX = 24
sizeY = 10
scale = 1
START_STOP_KEY = 0x55 --or 'U'
RESET_KEY = 0x4A --or 'J'
--
--[[
Timer Module Script by SebyGHG original script by Onix64(Stopwatch)
if you wish to change the key you can take the key code from here
https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
]] -------------script-code-------------
state = 1
stopTime = 0
startTime = 0
f = io.input("timesave.txt")
result = f :read()
f :close()
stopTime = result
state = 2
function keyboard(key, isDown)
if (isDown == true) then
if (key == RESET_KEY) then
state = 0
elseif (key == START_STOP_KEY) then
if (state == 0) then
state = 1
startTime = os.time()
elseif (state == 1) then
state = 2
io.output("timesave.txt")
timesave= (io.open("timesave.txt","w"))
io.write(stopTime)
io.close(timesave)
stopTime = os.time() -stopTime
elseif (state == 2) then
state = 1
startTime =startTime + os.time() - stopTime
end
end
end
end
TimerText = "00:00"
TextColor = {r = 30, g = 255, b = 30, a = 255}
function doubleDigit(number)
if (number < 10) then
return "0" .. math.floor(number)
else
return math.floor(number)
end
end
function timeText(time)
local result = ""
local days = 0
while (time > 86399) do
days = days + 1
time = time - 86400
end
local hours = 0
while (time > 3599) do
hours = hours + 1
time = time - 3600
end
local minutes = 0
while (time > 59) do
minutes = minutes + 1
time = time - 60
end
if (days == 0) then
if (hours == 0) then
return doubleDigit(minutes) .. ":" .. doubleDigit(time)
else
return math.floor(hours) .. " : " .. doubleDigit(minutes) .. ":" .. doubleDigit(time)
end
else
return math.floor(days) ..
" : " .. doubleDigit(hours) .. " : " .. doubleDigit(minutes) .. ":" .. doubleDigit(time)
end
end
function update()
if (state == 0) then
TextColor = {r = 255, g = 0, b = 0, a = 255}
TimerText = "00:00"
elseif (state == 1) then
TimerText = timeText(os.time() - startTime)
TextColor = {r = 0, g = 255, b = 255, a = 255}
elseif (state == 2) then
TimerText = timeText(stopTime - startTime)
TextColor = {r = 255, g = 255, b = 0, a = 255}
end
end
function render()
local font = gui.font()
local tw = font.width(TimerText)
gfx.color(0, 0, 0, 0)
gfx.rect(0, 0, tw + 4, 10)
gfx.color(TextColor.r, TextColor.g, TextColor.b, TextColor.a)
gfx.text(2, 1, TimerText)
end
It looks like you are saving the Unix Timestamp to your file, you can try and make it human readable using an online time converter (https://time.is/Unix_time_converter)
Besides this, take some time to read the os.time() implementation details on this lua page: https://www.lua.org/pil/22.1.html
The time function, when called without arguments, returns the current date and time, coded as a number. (In most systems, that number is the number of seconds since some epoch.)
If you want the time in between certain action, save the initial timestamp and diff it at the end of the action. This is natively supported in lua using os.difftime(). (http://www.lua.org/manual/5.3/manual.html#pdf-os.difftime)

Power Query M Recursively Creating a "Flat" List from a Multidimensional List

In Power Query M I am trying to create a recursive function that will turn a mess of multidimensional lists and records into one flat list of records, so that the records can be easily manipulated in PowerBI.
I have worked with recursion in other languages but I am quite new to using M.
The mess of lists and records is similar in structure to this:
Event
Event Details
Payments
Payment Details
There are some minor differences but they shouldn't matter.
I am hoping the output will be similar to this:
{
[event1, eventDetail1, payment1, paymentDetails1],
[event1, eventDetail1, payment1, paymentDetails2],
[event1, eventDetail1, payment1, paymentDetails3],
[event1, eventDetail1, payment2, paymentDetails1],
}
Continuing on for every single item.
This is the recursive function I have currently:
recursiveCollapse = (uncleanedList as list, eventCounter as number, paymentCounter as number, finalList as list) =>
let
eventLength = List.Count(uncleanedList),
firstIf = if eventCounter < eventLength then
let
secondIf = if paymentCounter < List.Count(uncleanedList{eventCounter}[eventPayments]) then
finalList = #recursiveCollapse(uncleanedList, eventCounter, paymentCounter + 1, finalList & {
[
EventName = uncleanedList{eventCounter}[eventDetailName],
EventDescription = uncleanedList{eventCounter}[eventDetailDescription],
EventSaleStatus = uncleanedList{eventCounter}[eventDetailStatus],
EventFirstDate = uncleanedList{eventCounter}[eventDetailFirst],
EventLastDate = uncleanedList{eventCounter}[eventDetailLast],
PaymentID = uncleanedList{eventCounter}[eventPaymentDetails][refs]{paymentCounter}[id],
PaymentName = uncleanedList{eventCounter}[eventPaymentDetails][refs]{paymentCounter}[name],
PaymentCreated = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][created],
CustomerEmail = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][customer][emailAddress],
CustomerFirstName = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][customer][firstName],
CustomerLastName = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][customer][lastName],
CustomerPhone = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][customer][mobilePhone],
PaymentStatus = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][status],
PaymentTotal = uncleanedList{eventCounter}[eventPayments]{paymentCounter}[paymentDetail][totalPrice][value]
]
})
else
finalList = #recursiveCollapse(uncleanedList, eventCounter + 1, 0, finalList)
in
finalList
else
finalList
in
finalList,
dataTable = recursiveCollapse(allEventsLinks, 0, 0, {})
in
dataTable
At this stage "dataTable" is just returned as an empty table.
I believe the problem is due to the "finalList" not being returned correctly through the recursive calls of the function. M does not have a return keyword, so I am lost on what to do from here.
Any help is appreciated.
Thanks
I figured it out.
To anyone else who needs help with this here is my solution:
recursiveCollapse = (uncleanedList as list, eventCounter as number, paymentCounter as
number, finalList as list) =>
let
returnList =
let
eventLength = List.Count(uncleanedList),
eventIf = if eventCounter < eventLength then
let
eventReturn = if paymentCounter + 1 < List.Count(uncleanedList{eventCounter}[eventPayments]) then
let
addRow =
finalList &
{
[
EventName = uncleanedList{eventCounter}[eventDetailName],
EventDescription = uncleanedList{eventCounter}[eventDetailDescription],
EventSaleStatus = uncleanedList{eventCounter}[eventDetailStatus],
EventFirstDate = uncleanedList{eventCounter}[eventDetailFirst],
EventLastDate = uncleanedList{eventCounter}[eventDetailLast],
PaymentID = uncleanedList{eventCounter}[eventPaymentDetails][refs]{paymentCounter + 1}[id],
PaymentName = uncleanedList{eventCounter}[eventPaymentDetails][refs]{paymentCounter + 1}[name],
PaymentCreated = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][created],
CustomerEmail = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][customer][emailAddress],
CustomerFirstName = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][customer][firstName],
CustomerLastName = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][customer][lastName],
CustomerPhone = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][customer][mobilePhone],
PaymentStatus = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][status],
PaymentTotal = uncleanedList{eventCounter}[eventPayments]{paymentCounter + 1}[paymentDetail][totalPrice][value]
]
},
recursion = #recursiveCollapse(uncleanedList, eventCounter, paymentCounter + 1, addRow)
in
recursion
else
let
recursion = #recursiveCollapse(uncleanedList, eventCounter + 1, 0, finalList)
in
recursion
in
eventReturn
else
finalList
in
eventIf
in
returnList,
dataTable = Table.FromList(recursiveCollapse(allEventsLinks, 0, 0, {}), Record.FieldValues, {
"EventName",
"EventDescription",
"EventSaleStatus",
"EventFirstDate",
"EventLastDate",
"PaymentID",
"PaymentName",
"PaymentCreated",
"CustomerEmail",
"CustomerFirstName",
"CustomerLastName",
"CustomerPhone",
"PaymentStatus",
"PaymentTotal"
})
in
dataTable

Moment.js show diff between 2 dates

I use moment(d, "YYYYMMDD").fromNow(); to get diff between date now and some date, but I would like to get without string "a few days ago".
Instead, I would like to get "7d" (7m, 1s, etc).
How can I do this?
If you want just to get the difference between two dates instead of a relative string just use the diff function.
var date = moment("20170101", "YYYYMMDD");
var date7 = moment("20170108", "YYYYMMDD");
var mins7 = moment("20170101 00:07", "YYYYMMDD HH:mm");
var secs1 = moment("20170101 00:00:01", "YYYYMMDD HH:mm:ss");
console.log(date7.diff(date, "days") + "d"); // "7d"
console.log(mins7.diff(date, "minutes") + "m"); // "7m"
console.log(secs1.diff(date, "seconds") + "s"); // "1s"
Moment.diff does exactly that.
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b) // 86400000
You can specify a unit:
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days') // 1
var before = moment('2017.02.12 09:00','YYYY.MM.DD HH:mm');
var now = moment();
console.log(
moment(now - before)
.format('D[ day(s)] H[ hour(s)] m[ minute(s)] s[ second(s) ago.]')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>

how to get records from database based on date range in asp.net linq

I have develop a small web application in that i'm using entity frame work .i want get the records based on the date range and bind that data in gridview how can i write a query using linq..please help me..Here i have post my code what i have try to get records please .....
var query = from p in entity.Payments
join D in entity.Debit_Method on p.Debit_Method_ID equals D.Debit_Method_ID
join pt in entity.Payment_Type on p.Payment_Type_ID equals pt.Payment_Type_ID
where p.Client_Pmt_Date >='1998-12-01' && p.Client_Pmt_Date<='1999-08-01' && p.Loan_ID=loanid
select new
{
p.Pmt_ID,
p.Loan_ID,
p.Client_Pmt_Date,
p.MtgSvr_Pmt_Start_Date2,
D.Debit_Method_Desc,
p.Total_Debit_Amt,
p.CreditAmt,
p.LenderAmt,
pt.Payment_Type_Desc,
p.Return_Code,
p.Returned_Date
//p.Pmt_ID,
// D.Debit_Method_Desc,
// pt.Payment_Type_Desc,
// p.Client_Pmt_Date,
// p.MtgSvr_Pmt_Start_Date2,
// p.Amt,
// p.CreditAmt,
// p.Loan_ID,
// p.Pmt_Comments
// p.Loan_ID,
};
grdPayments.DataSource = query.ToList();
grdPayments.DataBind();
}
You will need to compare the Date to a DateTime object rather than a string. Here is a LINQ example with POCO (Plain Old CLR Objects):
var dates = new List<DateTime> { new DateTime(2011, 1, 1), new DateTime(2010, 1, 1), new DateTime(2009, 1, 1) };
var result1 = from x in dates where x < new DateTime(2011, 1, 1) && x > new DateTime(2009,1,1) select x;
var result2 = dates.Where(x => x < new DateTime(2011, 1, 1) && x > new DateTime(2009,1,1));

Entity Framework and Linq - Comparing DateTime

I have this code
public List<CalendarData> GetCalendarData(DateTime day)
{
List<CalendarData> list = new List<CalendarData>();
using (dataContext = new VTCEntities())
{
DateTime test = new DateTime(2010, 10, 20, 17, 45, 0);
var data = from z in dataContext.ReservationsSet
where z.start_time.Value == test
select z;
foreach (var r in data)
What I'd like to do is have this
var data = from z in dataContext.ReservationsSet
where z.start_time.Value == day
select z;
the problem I have is that z.start_time has the time part also. The DateTime day doesn't have the time part recorded. Is there a way to compare the the date part of without getting this error
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
when I do this
var data = from z in dataContext.ReservationsSet
where z.start_time.Value.Date == test
select z;
One option is to compute two values, like this:
DateTime day = ...;
DateTime nextDay = day.AddDays(1);
var data = from z in dataContext.ReservationsSet
where z.start_time.Value >= day &&
z.start_time.Value < nextDay
select z;
You can't use .Date in Entity Framework. The easiest way I know to handle this is to make a minimum + maximum day:
DateTime test = new DateTime(2010, 10, 20, 17, 45, 0);
DateTime startDay = test.Date;
DateTime endDay = startDay.AddDays(1);
var data = from z in dataContext.ReservationsSet
where z.start_time.Value >= startDay && z.start_time.Value < endDay
select z;

Resources