Refreshing view panel from dojo widget - dojo

Got this code from #MichaelSaiz and altered it slightly, and the calendar widget looks/works great with the Calendar.css that comes with dojo 1.5.x on the Domino server.
However, I need to refresh a Calendar view when the user clicks on a date, and although fields are being refreshed OK, the view is behaving strangely, and I can't see why?
XSP.addOnLoad(function(){
dojo.require("dojox.widget.Calendar");
dojo.require("dojo.date","dijit.registry");
dojo.require("dojo.date.locale");
dojo.require("dijit.Calendar");
dojo.ready(function(){
// create the Calendar:
var selectedDate = null;
var calendar_body = new dojox.widget.Calendar({
value: new Date(),
onValueSelected: function(date){calendarDateClicked(date);
}
}, "calendar_body");
//create Click action
function calendarDateClicked(date){
var d = new Date(date);
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
var dateString = [day,month,year].join("/");
var y = dojo.date.locale.format(d, {datePattern:"dd/MM/yyyy", selector: 'date'});
//dojo.byId('#{id:hiddenCalWidgetSelectedDate}').value = dateString
dojo.byId('#{id:hiddenCalWidgetSelectedDate}').value = y;
dojo.byId('#{id:calDate}').value = y;
//dojo.byId('#{id:calDate}').value = dateString;
XSP.partialRefreshGet("#{id:dayPanel1}",{});//Post Value to server
}
});
});
This fires when the user clicks the calendar and it updates a field (calDate) and then updates the viewPanel (dayPanel1).
The view is filtered based on a calDate field which clicking on the calendar sets.
Any ideas how I can get the view refreshed when the user clicks on the calendar? Seems basic but it's driving me nuts!!
Graeme

The date format was incorrect (as #MichaelSaiz surmised). Got it sorted now.
XSP.addOnLoad(function(){
dojo.require("dojox.widget.Calendar");
dojo.require("dojo.date","dijit.registry");
dojo.require("dojo.date.locale");
dojo.require("dijit.Calendar");
dojo.ready(function(){
// create the Calendar:
var selectedDate = null;
var calendar_body = new dojox.widget.Calendar({
value: new Date(),
onValueSelected: function(date){calendarDateClicked(date);
}
}, "calendar_body");
//Set month in correct format
function setMonth(month){
switch(month)
{
case 1:
month = "Jan";
break;
case 2:
month = "Feb";
break;
}
return month;
}
//create Click action
function calendarDateClicked(date){
var d = new Date(date);
var month = (d.getMonth() + 1);
month = setMonth(month);
var day = '' + d.getDate() + ",";
var year = d.getFullYear();
//if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
var dateString = [month,day,year].join(" ");
//var y = dojo.date.locale.format(d, {datePattern:"dd/MM/yyyy", selector: 'date'});
dojo.byId('#{id:hiddenCalWidgetSelectedDate}').value = dateString
//dojo.byId('#{id:hiddenCalWidgetSelectedDate}').value = y;
//dojo.byId('#{id:calDate}').value = y;
dojo.byId('#{id:calDate}').value = dateString;
XSP.partialRefreshPost("#{id:mainPanel}",{});//Post Value to server
}
});
});

Related

Convert Date Milliseconds to Valid DateTime React Native

I'm trying to convert the Milliseconds date from Server to valid datetime but for some reason the code is not working on react native as expected on my other applications
const ToValidDateTime = (date: string) => {
console.log(date); //HERE Date Returned by server is ( /Date(1617048540000)/ )
date = date.replace(/\D/g, ''); //removing everything just taking digits
var fullDate = new Date(date);
console.log(fullDate); //here is just giving me Date { NaN }
var twoDigitMonth = fullDate.getMonth() + 1 + "";
if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
var twoDigitDate = fullDate.getDate() + "";
if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
var currentDate =
twoDigitMonth + "/" + twoDigitDate + "/" + fullDate.getFullYear();
return currentDate;
}
any ideas what am I doing wrong here?
Convert String to Number when you extract it from /Date(1617048540000)/
This should work
var fullDate = new Date(Number(date));
var date = "Date(1617048540000)"
console.log(date); //HERE Date Returned by server is ( /Date(1617048540000)/ )
date = date.replace(/\D/g, ''); //removing everything just taking digits
console.log(date)
var fullDate = new Date(Number(date));
console.log(fullDate.toDateString()); //here is just giving me Date { NaN }
var twoDigitMonth = fullDate.getMonth() + 1 + "";
if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
var twoDigitDate = fullDate.getDate() + "";
if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
var currentDate =
twoDigitMonth + "/" + twoDigitDate + "/" + fullDate.getFullYear();

How do I extract current date, month and year in the format yyyy-mm-dd in karate dsl?

* def date =
"""
function(s) {
var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
return sdf.parse(s).time;
}
"""
Currently, I'm using this. Any help is much appreciated.
You can also archive the following by using javascript as follows:
* def todaysDate =
"""
function()
{
var d=new Date();
var month = String(d.getMonth() + 1);
var day = String(d.getDate());
var year = String(d.getFullYear());
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return year+'/'+month+'/'+day
}
"""
* print todaysDate()
Here you go:
* def today =
"""
function() {
var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
var sdf = new SimpleDateFormat('yyyy-MM-dd');
return sdf.format(new java.util.Date());
}
"""
* print today()

how do I change this google app script to hide sheets columns instead of rows based on column dates

so I'm a long way form a competent programmer, but I do dabble in google sheets scripts.
I previously had a script running on a timer trigger to hide rows based on dates found in column A.
function min() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("A:A").getValues();
var today = new Date().getTime() - 86400000‬
for (var i = s.getLastRow(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u < today) {
s.hideRows(i);
}
}
}
}
function max() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("A:A").getValues();
var today = new Date().getTime() + 86400000
for (var i = s.getLastRow(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u > today) {
s.hideRows(i);
}
}
}
}
function SHOWROWS() {
// set up spreadsheet and sheet
var ss = SpreadsheetApp.getActiveSpreadsheet(), sheets = ss.getSheets();
for(var i = 0, iLen = sheets.length; i < iLen; i++) {
// get sheet
var sh = sheets[i];
// unhide rows
var rRows = sh.getRange("A:A");
sh.unhideRow(rRows);
}
}
this would be set to run at midnight every night so as to hide all rows not +-1 day from the current date.
I have now switched to using this document primarily through the android app I need to swap the input layout Moving dates from rows and values in columns to the inverse, values are now in rows and the dates are in columns, inputing vertical values would be much quicker....but honestly its more about understanding what im doing wrong thats really motivating my search for a answer.
can anyone help me modify my old script to work on this changed sheet.
my attempts fall flat..eg:
function min() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("1:1").getValues();
var today = new Date().getTime() - 86400000‬
for (var i = s.getLastColumn(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u < today) {
s.hidecolumns(i);
}
}
}
}
example spreadsheet:
https://docs.google.com/spreadsheets/d/1EjRIeDPrG_qp1S9QhInl9r3G0cZx_16OvnTXORgA3n4/edit?usp=sharing
there is two sheets one with the old version of my layout called "OLD" and my new desired layout called "NEW"
thanks in advance to anyone able to help
This function hides a column whose top row date is less yesterday.
function hideColumnWhenTopRowDateIsBeforeYesterday() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sh=ss.getSheetByName("Sheet1");
var rg=sh.getRange(1,1,1,sh.getLastColumn());
var vA=rg.getValues()[0];
var yesterday=new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1).valueOf();
vA.forEach(function(e,i){
if(new Date(e).valueOf()<yesterday) {
sh.hideColumns(i+1);
}
});
}
My Spreadsheet before hiding columns:
My Spreadsheet after hiding columns:

EPPlus two color conditional date format

I have a column with dates and I want to conditionally color any cell that is older that 2 week yellow, and any that is older than 90 days red. I can't figure out how to do that.
Should be able to just add the conditions like any other. You can use the TODAY() function in excel and subtract:
[TestMethod]
public void Conditional_Formatting_Date()
{
//https://stackoverflow.com/questions/56741642/epplus-two-color-conditional-date-format
var file = new FileInfo(#"c:\temp\Conditional_Formatting_Date.xlsx");
if (file.Exists)
file.Delete();
//Throw in some data
var dataTable = new DataTable("tblData");
dataTable.Columns.AddRange(new[] {
new DataColumn("Col1", typeof(DateTime)),
new DataColumn("Col3", typeof(string))
});
var rnd = new Random();
for (var i = 0; i < 100; i++)
{
var row = dataTable.NewRow();
row[0] = DateTime.Now.AddDays(-rnd.Next(1, 100));
row[1] = $"=TODAY() - A{i +1}";
dataTable.Rows.Add(row);
}
//Create a test file
using (var package = new ExcelPackage(file))
{
//Make the stylesheet
var ws = package.Workbook.Worksheets.Add("table");
var range = ws.Cells[1, 1].LoadFromDataTable(dataTable, false);
ws.Column(1).Style.Numberformat.Format = "mm-dd-yy";
ws.Column(1).AutoFit();
//Add the calc check
var count = 0;
foreach (DataRow row in dataTable.Rows)
ws.Cells[++count, 2].Formula = row[1].ToString();
//Add the conditions - order matters
var rangeA = range.Offset(0, 0, count, 1);
var condition90 = ws.ConditionalFormatting.AddExpression(rangeA);
condition90.Style.Font.Color.Color = Color.White;
condition90.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition90.Style.Fill.BackgroundColor.Color = Color.Red;
condition90.Formula = "TODAY() - A1> 90";
condition90.StopIfTrue = true;
var condition14 = ws.ConditionalFormatting.AddExpression(rangeA);
condition14.Style.Font.Color.Color = Color.Black;
condition14.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition14.Style.Fill.BackgroundColor.Color = Color.Yellow;
condition14.Formula = "TODAY() - A1> 14";
package.Save();
}
}
Which gives this in the output:
I am assuming that you have the column number of the date column and number of rows in your records. Also, the following loop is under assumption that the first row is your column header and records begin from second row. Change the loop counter's initialization and assignment accordingly.
int rowsCount; //get your no of rows
int dateColNumber; //Assign column number in excel file of your date column
string cellValue;
DateTime dateValue;
DateTime today = DateTime.Now;
double daysCount;
for(int i=1;i<rowsCount;i++)
{
cellValue = ws.Cells[i + 1, dateColNumber].Text.ToString(); //First row is header start from second
if(DateTime.TryParse(cellValue,out dateValue))
{
daysCount = (today - dateValue).Days;
if(daysCount>90)
{
ws.Cells[i + 1,dateColNumber].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
ws.Cells[i + 1,dateColNumber].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);
}
else if(daysCount>14)
{
ws.Cells[i + 1, dateColNumber].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
ws.Cells[i + 1, dateColNumber].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Yellow);
}
}
}

placing movie clips around a 24hr clock face (as2) - time management

I am currently working on a project to plot the activities of my day out by placing them around a 24 hr clock face. the final out come of this is a time management app that allows you to find spaces in your day that could be used more proficiently; however; I have hit a bit of a snafu and that is assigning each movie clip (each of which represents an activity) to its correct place of on the clock face.
I am using an XML file to pull the times from and the calculation of the angle where the movie clip should be placed on the clock is done in relation to a central movie clip.
for (i = 0; i < TimeSheet.length; i++) {
var counter = i + 1;
sortXML(TimeSheet);
}
}
};
function sortXML(TimeSheet){
var activity = TimeSheet[i].firstChild.nodeValue;
var description = TimeSheet[i].firstChild.nextSibling.childNodes;
var HrStart = TimeSheet[i].firstChild.nextSibling.nextSibling.childNodes;
var MinStart = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.childNodes;
var HrEnd = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var MinEnd = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var place = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var creativity = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var usefulness = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var enjoyment = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
var focus = TimeSheet[i].firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes;
category = TimeSheet[i].nodeName;
HourStart = parseInt(HrStart, 10);
MinuteStart = parseInt(MinStart, 10);
HourEnd = parseInt(HrEnd, 10);
MinuteEnd = parseInt(MinEnd, 10);
Creativity = parseInt(creativity, 10);
Focus = parseInt(focus, 10);
Usefulness = parseInt(usefulness, 10)
var TimeSpent = ((HourEnd*60)+MinuteEnd) - ((HourStart*60)+MinuteStart) ;
//var ActivityMinutes = (HourStart*60)+MinuteStart;
var TimeStart = (HourStart*60)+MinuteStart;
var BobPlacement = ((TimeStart/1440)*360) // where the bob gets blaced on the circle
//var BobPlacement = (360/1440)*TimeStart;
//var radius = 150 + Usefulness;
var radius = 200 + (Usefulness/2);
var xcenter = _root.bobCentral._x;
var ycenter = _root.bobCentral._y;
var degree = (BobPlacement + 180)*-1;;
var radian;
radian = (degree/180)*Math.PI;
newBob._x = xcenter+Math.cos(radian)*radius;
newBob._y = ycenter-Math.sin(radian)*radius;
/*trace("-----------------------------------");
trace("category = "+category);
trace("activity = " + activity);
trace("Description = " + description);
trace("time start = " + HourStart + ":" + MinuteStart);
trace("time end = " + HourEnd + ":" + MinuteEnd);
trace("Duration of activity = "+TimeSpent);
trace("place = "+ place);
trace("creativity = "+ creativity);
trace("usefulness = "+ usefulness);
trace("enjoyment = "+ enjoyment);
trace("focus = "+ focus);
trace("Time Started = "+ TimeStart);
trace("palce on circle = "+ BobPlacement);
*/
dupeMC(TimeSheet, category, activity, description, HourStart, MinuteStart, TimeSpent, Creativity, Focus, Usefulness);
}
function dupeMC(TimeSheet, category, activity, description, HourStart, MinuteStart, TimeSpent, Creativity, Focus, Usefulness){
bob.duplicateMovieClip("bob"+i, i);
newBob = eval("bob"+i);
Any help would be much appreciated
I apologies in advance if the way I have put this question forward is confusing in any way.