Display separate text strings each day - html

I want to display a text string, or a bit of code each day of the week for two weeks, then it will repeat. So through the days it will display Monday 1, Tuesday 1...Friday 1, Monday 2, Tuesday 2...Friday 2. Then it will revert back to Monday 1. If there is a way without using I-frame (have to spell like this so it will let me post the question) from another site then please say. I have tested out with I-frame but it never seems to work. So maybe a counter which when reaching 14 will revert to 1 again. Thank you in advance!

You should be able to achieve it with pure JavaScript using the following:
Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
var dayOfYear = ((today - onejan +1)/86400000);
return Math.ceil(dayOfYear/7)
};
var sentences = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelvth", "thirsteenth", "fourteenth"];
var date = new Date();
var day = (date.getDay()+6)%7+1;
day = day * ((date.getWeek()%2)+1);
document.getElementById("container").innerHTML = sentences[day-1];
Fiddle: https://jsfiddle.net/04wha99e/1/
Using simple JavaScript, you create an array of sentences you wish to have, and basically get the current day of the week (JavaScript Date.getDay() returns Sunday as 0, hence the workaround) and based on the week number being odd or even you multiply it by 1 on 2 getting a range of 1-14 and then return the sentence from the array (starting index 0, hence the minus 1)
The above script assumes, you have a div with the id container, where the inner html gets replaced:
<div id="container">
This is where the sentence goes
</div>

Related

How to process csv data (datetime) month, week, day, hour in highstock highcharts

I have a CSV file with following format:
<pre id="csv" style="display:none">
DATES,WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER
01/10/2018 00:00,25,16,13,1,0
01/10/2018 01:00,24,5,9,3,2
01/10/2018 02:00,28,6,17,0,6
The data range is 01/10/2018 00:00 - 31/10/2018 00:00
Interval is every hour.
I am using highstock stacked column with 5 categories: WHOLESALE,ECOMMERCE,RETAIL,LOANS,BONDISSUER.
My problem is, that the highstock navigator displays the data incorrectly. I think I have to customise property in range selector or navigator, but I can't find any documentation online. I tried inputDateParser, but it didn't work. Here is the jsfiddle
inputDateParser: function (value) {
value = value.split(/[:\.]/);
return Date.UTC(
1970,
0,
1,
parseInt(value[0], 10),
parseInt(value[1], 10),
parseInt(value[2], 10),
parseInt(value[3], 10)
);
}
How do I get the data range to be correct: month of October 2018 according to the dates in CSV?
I should not see a whole year in the navigator, when I only have data for October.
Thanks much appreciated
You would need to format the dates correctly, it can be done using the beforeParse callback function, like this:
data: {
csv: document.getElementById('csv').innerHTML,
beforeParse: function(e) {
let csv = e.split('\n'); //split by newline
let processedTable = []
processedTable.push(csv[0].split(','))
for (let i = 1; i < csv.length; i++) {
let row = csv[i].split(',');
if (row.length != 6) //skip empty rows or rows with more/less columns
continue;
let date = row[0].split(' ')[0].split('/')
let time = row[0].split(' ')[1].split(':')
processedTable.push(
[(new Date(date[2], date[1] - 1, date[0], time[0], time[1], 0)).getTime(), //get the timestamp for the date
parseInt(row[1]),
parseInt(row[2]),
parseInt(row[3]),
parseInt(row[4]),
parseInt(row[5])
].join(',')
)
}
return processedTable.join('\n') //join the array into a string again
},
},
Every row is parsed, by splitting it apart, the date is found, and milliseconds since 1970 is returned by getTime(). Then we join the cells into strings, and lastly the rows into a long string. The reason we convert this back into a string, is because highcharts is going to read it in from a string.
Working JSFiddle example: https://jsfiddle.net/ewolden/spmtgv3a/
API on beforeParse: https://api.highcharts.com/highcharts/data.beforeParse

Bootstrap DatePicker, how to set the start date as next day 12AM?

I was trying to make use of bootstrap date picker, and make the user to select next day or above in the calendar.
How to make the (data-date-start-date="12AM next day") instead of (data-date-start-date="+1d").
To be precise, the selected insurance policy needs be covered from next day 12AM.
I'm banging my head from last couple of days, tried most of the known probabilities.
It needs to be set via Bootstrap date picker! Any help would be highly appreciated.
<div class="input-group date" data-provide="datepicker" data-date-autoclose="true" data-date-start-view="0" data-date-force-parse="false" data-date-start-date="+1d"></div>
Try this:
<script type="text/javascript">
$(function () {
var d = new Date();
d.setDate(d.getDate() + 1); //this will set tomorrow
d.setHours(0, 0, 0, 0); //this will set 12 AM
$('#datetimepicker1').datetimepicker({
defaultDate: d,
});
});
</script>
bootstrap-datepicker is not designed to be concerned with time (search the documentation for the word "time").
There are other libraries that help with picking dates and times.

AngularJS how to sum data from database in the view

I have a table, with one column for each day of the week, in which with a ng-repeat, I put the hours worked on a specific project in that week.
The data gets pulled from a database.
What I'm having trouble with is, each project can have different subprojects, and when this happens, they all get put in a rowspan under the same main project, as you can see in the image ( the "SU" Project has 2 subprojects "ghfgh" and "testtesttest").
Now, the total hours in the last column gets pulled as well from the database, where all the hours of a project in a specific week are summed.
How can I make that IF a project has subprojects, their hours that week get summed in a single rowspan as well? (in the image I put an arrow showing the result wanted)
If I use the same code to give the rowspan to the subprojects, it gives the right rowspan to the total column, but obviously only shows the hours of the first subproject (in this case "ghfgh")
<tr ng-repeat="p in vm.presences">
<td ng-if="p.showProject" rowspan="{{p.projectCount}}">{{p.projectName}}</td>
<td>{{p.description}}</td>
<td>{{p.monday}}</td>
<td>{{p.tuesday}}</td>
<td>{{p.wednesday}}</td>
<td>{{p.thursday}}</td>
<td>{{p.friday}}</td>
<td>{{p.saturday}}</td>
<td>{{p.sunday}}</td>
<td ng-if="p.showProject" rowspan="{{p.projectCount}}">{{p.total}}</td>
</tr>
and the code used to check if there are multiple entries of the same project in a given week, to group them in the same rowspan is
weeklyPresences.forEach((p, i) => {
const differentProject = i === 0 || weeklyPresences[i - 1].projectName !== p.projectName;
p.showProject = differentProject;
if (differentProject) {
p.projectCount = weeklyPresences.filter(pres => pres.projectName === p.projectName).length;
} else {
p.projectCount = weeklyPresences[i - 1].projectCount;
}
});
return weeklyPresences;
any idea on how I could group the hours of the subprojects?
I was thinking about some loop that checks if a project has multiple entries like the code above, if it doesn't, the var total stays the same, otherwise, it takes them and sums them in a new var.
var arr= [1, 2, 3];
var sum = arr.reduce((a, b) => a + b, 0);
console.log(sum); // 6

Date : Converting AM to PM, and PM to AM

Perhaps a stupid question, but i really dont know the answer :(
lets say i have a date object, how can i change its AM date to PM, or vice verca?
Thanks
seems like you can
var currentTime = new Date();
var hours:uint = currentTime.getHours();
then you can say, if hours is greater than or equal to 12, then subtract by 12, otherwise, add 12 to it, for example, by
public static const millisecondsPerHour:int = 1000 * 60 * 60;
var reversedAMPM = new Date(currentTime.getTime() + (12 * millisecondsPerHour));
Although Jian's version should work, here's an alternative.
Assuming var date:Date is initialized, you may literally change it:
date.hours += (date.hours > 12) ? -12:12;

TimeDelta class in ActionScript?

Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.