Youtrack workflow via JS - Unable to compare estimation and spent time - youtrack

I just want to compare 2 periods (e.g. i want to compare between 3w4d23h58m and 20h in order to track time). All i got is
I need to convert this PT2H to just 2 hours to count percentage between estimation and spent time.
https://www.jetbrains.com/help/youtrack/devportal/v1-PeriodProjectCustomField.html?q=getMinutes

Here is an excerpt from a workflow that calculates remaining time by subtracting spent time from estimation:
action: (ctx) => {
const issue = ctx.issue;
var periodestimate = issue.Estimation;
var minutesestimate = !periodestimate ? 0 : (periodestimate.getMinutes() + 60 * (periodestimate.getHours() + 8 * (periodestimate.getDays() + 5 * periodestimate.getWeeks())));
var periodspent = ctx.issue.fields.SpentTime;
var minutesspent = !periodspent ? 0 : (periodspent.getMinutes() + 60 * (periodspent.getHours() + 8 * (periodspent.getDays() + 5 * periodspent.getWeeks())));
var remain = minutesestimate - minutesspent;
ctx.issue.fields.Remaining = dateTime.toPeriod(remain + 'm');
},
I suppose that you can use it as an example to calculate the needed percentage.

Related

Reducing time querying Scalikejdbc

I own an amount about 80 000 rows on 3 tables of database, every time I execute my code, it can take 4-5 minutes to display the result. Do you know if it's possible to reduce this time by adding whatever ?
def findAirportAndRunwayByCountry(code: String)(implicit session : DBSession = AutoSession) : List[(Airports,Runway)] = {
val (c, a, r) = (Country.syntax("c"), Airports.syntax("a"), Runway.syntax("r"))
withSQL { select.from(Airports as a).innerJoin(Runway as r).on(r.ID, a.ID).innerJoin(Country as c).on(c.Code, a.Country).where.eq(c.Code, code).or.like(c.Name, code + "%") }.map(rs => (Airports(rs),Runway(rs))).list.apply()
}
This is the code taking the time described (~4-5 mins)

How to change time formate in 24 in React-big-calender slots

let start = moment(el.StartDate).format('HH:mm')
not able to change the 24 hours format in react-big-calender please help me
let start = moment(el.StartDate).format("hh:mm a")
this should work.
but In case it didn't work here is another solution.
This assumes s is either 3 characters (930) or 4 characters (2130) but does absolutely no other validation.
function militaryTimeTo12Hour(s) {
if(s.length == 3) s = `0${s}`; // 930 -> 0930
const hour = parseInt(s.substring(0, 2), 10);
const min = parseInt(s.substring(2, 4), 10);
if(hour < 12) return `${hour % 12}:${min} AM`;
return `${hour % 12 || 12}:${min} PM`;
}
resource : https://stackoverflow.com/a/68575347/6654562

how to Calculate sum of multiple durations moment-js?

I am tryng to calculate w total working hours of each user what I did is getting the duration of each day, now I want to calculate the total working hours Given this input
durations:[ '0:30:00', '0:30:00', '0:30:00', '1:00:00' ] being respectively half an hour each and the last element being one hour ,
now I want to be able to sum all of these duration to get the total working hours
Here's what I managed to do to get the duration I am open to all of your suggestions to improve my already existing code and get my wanted result which is totalHours=HH:mm:ss
let startTime = moment(book.startTime, 'hh:mm:ss');
let endTime = moment(book.endTime, 'hh:mm:ss');
let totalSec = endTime.diff(startTime, 'seconds');
var durations = moment()
.startOf('day')
.seconds(totalSec)
.format('H:mm:ss');
result.push(durations);
Convert each duration to miliseconds
Get the sum of those miliseconds
Create moment object to format to hms
const durations = [ '0:30:00', '0:30:00', '0:30:00', '1:00:00' ];
const ms = durations.map(d => moment.duration(d).asSeconds() * 1000);
const sum = ms.reduce((prev, cur) => prev + cur, 0);
const hms = moment.utc(sum).format("HH:mm:ss");
console.log('HMS: ' + hms);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.32/moment-timezone-with-data.min.js"></script>
HMS: 02:30:00

Calculate the difference between two dates in React Native

I need to calculate the difference between two dates in days
i bring today date: new Date().toJSON().slice(0, 10) = 2019-04-17
and the other date in the same form
var msDiff = new Date("June 30, 2035").getTime() - new Date().getTime(); //Future date - current date
var daysTill30June2035 = Math.floor(msDiff / (1000 * 60 * 60 * 24));
console.log(daysTill30June2035);
You can implement it yourself, but why would you? The solution to that already exists, and somebody else has taken care (and still is taking care) that it works as it should.
Use date-fns.
import differenceInDays from 'date-fns/difference_in_days';
If you really want to bash your head, you can get difference in milliseconds and then divide by number of milliseconds in a day. Sounds good to me, but I'm not 100% sure if it works properly.
const differenceInDays = (a, b) => Math.floor(
(a.getTime() - b.getTime()) / (1000 * 60 * 60 * 24)
)
If you manipulate many dates, maybe an external library like moment.js could be useful. There are multiple add-ons like the date range one.
Once installed, you need to create a range
const start = new Date(2011, 2, 5);
const end = new Date(2011, 5, 5);
const range = moment.range(start, end);
Then could get the difference by doing something like
range.diff('months'); // 3
range.diff('days'); // 92
range.diff(); // 7945200000
Hope it could be useful :)
var d1 = new Date("2019/04/17") //firstDate
var d2 = new Date("2011/02/01") //SecondDate
var diff = Math.abs(d1-d2); //in milliseconds
Use differenceInDays, parseISO from "date-fns"
import DateTimePicker from "#react-native-community/datetimepicker";
import { differenceInDays, parseISO } from "date-fns";
let day = differenceInDays(
parseISO(your end date),
parseISO(yout first Date)
);
console.log("differenceInDays",differenceInDays)

Save object or array in collection variables to have range of numbers to compare in test

Currently, I encountered a small problem.
I have a goal: to test counter(functionality that calculates numbers) in order to check this counter returns a number that falls under set range of low and high (+-5% deviation)
Now, I have this piece of code:
var allLists = JSON.parse(responseBody);
var min = pm.variables.get("count"); // I separately extract min
var max = pm.variables.get("count1"); // and max, but want to extract one variable with min and max;
var low = parseInt(min)
var high = parseInt(max);
console.log("::MIN_VALIE: " + low + " | " + "::MAX_VALUE: " + high);
pm.test("test count", function () {
const value = allLists.data.count;
console.log(":::::::::=> COUNTER: " + value);
pm.expect(typeof value).to.eql('number');
pm.expect(value > low && value < high).to.eql(true);
});
It works ok, but I believe this code is bulky
In order to compare that value in the range of low and high I have to keep low and high number in collection variable, that out of desired 50 variables makes 100 variables and real mess.
Can I somehow keep one variable for low and high value in collection variables?
UPDATE:
Right after posting came up with it:
var allLists = JSON.parse(responseBody);
var num = pm.variables.get("count").split(',');
var min = parseInt(num[0]);
var max = parseInt(num[1]);
console.log("::MIN_VALIE: " + min + " | " + "::MAX_VALUE: " + max);
pm.test("test count", function () {
const value = allLists.data.count;
console.log(":::::::::=> COUNTER: " + value);
pm.expect(typeof value).to.eql('number');
pm.expect(15 > min && 15 < max).to.eql(true);
});
it's much better, but maybe exists better way
Resolved it with JSON.parse. In collection variable the range is written down as In Collection Varibles:
overall_count:[1,99] format, that I wanted to have.
var allLists = JSON.parse(responseBody);
// Here I parse this variable and make parse int to get integer and hurray, I have 1 variable instead of 2
const num = JSON.parse(pm.variables.get("overall_count")); //resolved it with JSON parsing
var min = parseInt(num[0]);
var max = parseInt(num[1]);
pm.test("test count", function () {
const value = allLists.data.count;
pm.expect(typeof value).to.eql('number');
pm.expect(15 > min && 15 < max).to.eql(true);
});