date-fns#intervalToDuration JavaScript Examples

The following examples show how to use date-fns#intervalToDuration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: helpers.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 6 votes vote down vote up
duration = (flight) => {
  const start = newDate(flight.flight_start);
  const end = newDate(flight.flight_end);
  const time = intervalToDuration({ start: new Date(start), end: new Date(end) });
  const h = time.hours !== 0 ? `${addZero(time.hours)}:` : '00:';
  const m = time.minutes !== 0 ? `${addZero(time.minutes)}:` : '00:';
  const s = time.seconds !== 0 ? `${addZero(time.seconds)}` : '00';
  return h + m + s;
}
Example #2
Source File: helpers.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 6 votes vote down vote up
durationMobile = (trip) => {
  const start = newDate(trip.trip_start);
  const end = newDate(trip.trip_end);
  const time = intervalToDuration({ start: new Date(start), end: new Date(end) });
  const h = time.hours !== 0 ? `${addZero(time.hours)}:` : '00:';
  const m = time.minutes !== 0 ? `${addZero(time.minutes)}:` : '00:';
  const s = time.seconds !== 0 ? `${addZero(time.seconds)}` : '00';
  return h + m + s;
}
Example #3
Source File: mobileAssets.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 6 votes vote down vote up
callSocketTrip = (q_mobile, map, selection) => {

  let flightPlanCoordinates = [];
  let polylinesArray = [];
  const marker = map.markers.find(el => el.id === q_mobile.name + '_marker')

  const infowindow = map.infowindows.find(el => el.id === q_mobile.name + '_infowindow')
  socket.on(`${q_mobile.name}_mobile`, async data => {
    console.log(data);
    const start = await lastStartTrip(q_mobile.name)
    const timer = intervalToDuration({ start: new Date(typeof start === 'string' ? new Date() : start.start_trip), end: new Date() })
    const latlngLine = latLng(data)
    await noParametersRequest('mobile_log_info_during_trip')
      .then(e => e.forEach(q_mobile => {
        if (data.ID === q_mobile.name) {
          flightPlanCoordinates.push(new google.maps.LatLng(data.lat, data.lon))
          const polyline = newPolyline(flightPlanCoordinates)
          addLine(polyline, map)
          polylinesArray.push(polyline)
        }
      }))
      .catch(e => null)
      infowindow.setContent(infoWindowM(data,q_mobile,timer))
      infowindow.open(map, marker);
    finishPolylinesTrip(q_mobile, polylinesArray);
  })
  finishTrip(q_mobile, selection)
  infowindow.close()
}
Example #4
Source File: simulationAssets.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 6 votes vote down vote up
drawTelemetry = async(flight, map, element)=> {
  const flightPlanCoordinates = [];
  const start = new Date(newDateLocal(flight.start));
  const end = new Date(newDateLocal(flight.end));
  const telemetry = await requestTelemetryFlight(flight.name, flight.start, flight.end); 
  const numberOfWaypoints = telemetry.length-1;
  const bounds = new google.maps.LatLngBounds();
  telemetry.forEach( (t,i)=> 
   {
  
    flight.position = JSON.stringify({'lat':parseFloat(t.lat),'lng':parseFloat(t.lon)})
    callOnceMarker(flagMarker,flight, map)
    setTimeout(()=>{
    const timer=intervalToDuration({start:start,end:end})
    flightPlanCoordinates.push(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
    const polyline = newPolyline(flightPlanCoordinates)
    map.markers[0].setPosition(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
    addLine(polyline,map)
    map.infowindows[0].setContent(infoWindowM(t,flight,timer))
    map.infowindows[0].open(map, map.markers[0]);
    polylinesArray.push(polyline)
    bounds.extend(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
    map.fitBounds(bounds);
    if(numberOfWaypoints===i) return stopFlight(flight,map,element)
  },i*1000)
})
}
Example #5
Source File: simulationMobileAssets.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 6 votes vote down vote up
drawTrip = async(trip, map, element)=> {
  toast(`Estamos cargando los datos del viaje del qHAWAX Móvil: ${trip.name}.`,'orange darken-1 rounded')
    const flightPlanCoordinates = [];
    const start = new Date(newDateLocal(trip.start));
    const end = new Date(newDateLocal(trip.end));
    const data = await requestQhawaxTrip(trip.name, trip.turn, trip.trip_id); 
    const numberOfWaypoints = data.length-1;
    const bounds = new google.maps.LatLngBounds();
    if(data.length>0){
      data.forEach( (t,i)=> 
     {
    
      trip.position = JSON.stringify({'lat':parseFloat(t.lat),'lng':parseFloat(t.lon)})
      callOnceMarker(flagMarker,trip, map)
      // setTimeout(()=>{
      const timer=intervalToDuration({start:start,end:end})
      flightPlanCoordinates.push(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
      const polyline = newPolyline(flightPlanCoordinates)
      map.markers[0].setPosition(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
      addLine(polyline,map)
      // map.infowindows[0].setContent(infoWindowM(t,trip,timer))
      // map.infowindows[0].open(map, map.markers[0]);
      polylinesArray.push(polyline)
      bounds.extend(new google.maps.LatLng({'lat':t.lat,'lng':t.lon}))
      map.fitBounds(bounds);
      if(numberOfWaypoints===i) return stopTrip(trip,map,element)//CHECK
    // },i*1000)
  })
    }
     else{
      toast(`No hay medidas para ${trip.name} `,'grey darken-1 rounded')
      setTimeout(()=>{goTo('tripMobileQ')},1000)
     }
    
  }
Example #6
Source File: droneAssets.js    From qAIRaMap-OpenSource with GNU General Public License v2.0 5 votes vote down vote up
callSocketFlight = (drone, map, selection) => {
  let flightPlanCoordinates = [];
  let polylinesArray = [];

  const marker=map.markers.find(el=>el.id===drone.name+'_marker')
  const infowindow = map.infowindows.find(el=>el.id===drone.name+'_infowindow')
  // const bounds = new google.maps.LatLngBounds();
    
		socket.on(`${drone.name}_telemetry`, async data => {
      const start = await lastStartFlight(drone.name)
      const timer=intervalToDuration({start:new Date(typeof start==='string'?new Date():start.start_flight),end:new Date()})
      latlngLine = {
        lat: parseFloat(data.lat),
        lng: parseFloat(data.lon),
      };
            await noParametersRequest('flight_log_info_during_flight')
            .then(e=>e.forEach(drone=>{
              if (data.ID===drone.name) {
                // console.log(data.ID,data.lat, data.lon);
                flightPlanCoordinates.push(new google.maps.LatLng(data.lat, data.lon))
                const polyline = newPolyline(flightPlanCoordinates)
              
                addLine(polyline,map)
                polylinesArray.push(polyline)
                // console.log(polylinesArray);
              }
            }))
            .catch(e=>null)
        marker.setPosition(latlngLine)
        infowindow.setContent(infoWindowT(data,drone,timer))
        infowindow.open(map, marker);
        // bounds.extend(new google.maps.LatLng(data.lat, data.lon))
        // map.fitBounds(bounds);
        socket.on(`${drone.name}_landing`, data => {
          // console.log(data);//condition with landing data by drone????
          polylinesArray.forEach(p=>{
            removeLine(p);
            polylinesArray = polylinesArray.filter(item => item !== p);
            // console.log('polylinesArray',polylinesArray);
            
            
          })
        });

    })
   landing(drone,selection)
   infowindow.close()
}
Example #7
Source File: index.js    From jellyfin-web-jmp with GNU General Public License v2.0 4 votes vote down vote up
function reloadFromItem(instance, page, params, item, user) {
    const apiClient = ServerConnections.getApiClient(item.ServerId);

    appRouter.setTitle('');

    // Start rendering the artwork first
    renderImage(page, item);
    // Save some screen real estate in TV mode
    if (!layoutManager.tv) {
        renderLogo(page, item, apiClient);
        renderDetailPageBackdrop(page, item, apiClient);
    }

    renderBackdrop(item);

    // Render the main information for the item
    page.querySelector('.detailPagePrimaryContainer').classList.add('detailRibbon');
    renderName(item, page.querySelector('.nameContainer'), params.context);
    renderDetails(page, item, apiClient, params.context);
    renderTrackSelections(page, instance, item);

    renderSeriesTimerEditor(page, item, apiClient, user);
    renderTimerEditor(page, item, apiClient, user);
    setInitialCollapsibleState(page, item, apiClient, params.context, user);
    const canPlay = reloadPlayButtons(page, item);

    setTrailerButtonVisibility(page, item);

    if (item.Type !== 'Program' || canPlay) {
        hideAll(page, 'mainDetailButtons', true);
    } else {
        hideAll(page, 'mainDetailButtons');
    }

    showRecordingFields(instance, page, item, user);
    const groupedVersions = (item.MediaSources || []).filter(function (g) {
        return g.Type == 'Grouping';
    });

    if (user.Policy.IsAdministrator && groupedVersions.length) {
        page.querySelector('.btnSplitVersions').classList.remove('hide');
    } else {
        page.querySelector('.btnSplitVersions').classList.add('hide');
    }

    if (itemContextMenu.getCommands(getContextMenuOptions(item, user)).length) {
        hideAll(page, 'btnMoreCommands', true);
    } else {
        hideAll(page, 'btnMoreCommands');
    }

    const itemBirthday = page.querySelector('#itemBirthday');

    if (item.Type == 'Person' && item.PremiereDate) {
        try {
            const birthday = datetime.parseISO8601Date(item.PremiereDate, true);
            const durationSinceBorn = intervalToDuration({ start: birthday, end: Date.now() });
            itemBirthday.classList.remove('hide');
            if (item.EndDate) {
                itemBirthday.innerHTML = globalize.translate('BirthDateValue', birthday.toLocaleDateString());
            } else {
                itemBirthday.innerHTML = `${globalize.translate('BirthDateValue', birthday.toLocaleDateString())} ${globalize.translate('AgeValue', durationSinceBorn.years)}`;
            }
        } catch (err) {
            console.error(err);
            itemBirthday.classList.add('hide');
        }
    } else {
        itemBirthday.classList.add('hide');
    }

    const itemDeathDate = page.querySelector('#itemDeathDate');

    if (item.Type == 'Person' && item.EndDate) {
        try {
            const deathday = datetime.parseISO8601Date(item.EndDate, true);
            itemDeathDate.classList.remove('hide');
            if (item.PremiereDate) {
                const birthday = datetime.parseISO8601Date(item.PremiereDate, true);
                const durationSinceBorn = intervalToDuration({ start: birthday, end: deathday });

                itemDeathDate.innerHTML = `${globalize.translate('DeathDateValue', deathday.toLocaleDateString())} ${globalize.translate('AgeValue', durationSinceBorn.years)}`;
            } else {
                itemDeathDate.innerHTML = globalize.translate('DeathDateValue', deathday.toLocaleDateString());
            }
        } catch (err) {
            console.error(err);
            itemDeathDate.classList.add('hide');
        }
    } else {
        itemDeathDate.classList.add('hide');
    }

    const itemBirthLocation = page.querySelector('#itemBirthLocation');

    if (item.Type == 'Person' && item.ProductionLocations && item.ProductionLocations.length) {
        let location = item.ProductionLocations[0];
        if (!layoutManager.tv && appHost.supports('externallinks')) {
            location = `<a is="emby-linkbutton" class="button-link textlink" target="_blank" href="https://www.openstreetmap.org/search?query=${encodeURIComponent(location)}">${escapeHtml(location)}</a>`;
        } else {
            location = escapeHtml(location);
        }
        itemBirthLocation.classList.remove('hide');
        itemBirthLocation.innerHTML = globalize.translate('BirthPlaceValue', location);
    } else {
        itemBirthLocation.classList.add('hide');
    }

    setPeopleHeader(page, item);
    loading.hide();

    if (item.Type === 'Book' && item.CanDownload && appHost.supports('filedownload')) {
        hideAll(page, 'btnDownload', true);
    }

    autoFocus(page);
}
Example #8
Source File: index.js    From veso-web with GNU General Public License v2.0 4 votes vote down vote up
function reloadFromItem(instance, page, params, item, user) {
    const apiClient = ServerConnections.getApiClient(item.ServerId);

    libraryMenu.setTitle('');

    // Start rendering the artwork first
    renderImage(page, item);
    // Save some screen real estate in TV mode
    if (!layoutManager.tv) {
        renderLogo(page, item, apiClient);
        renderDetailPageBackdrop(page, item, apiClient);
    }

    renderBackdrop(item);

    // Render the main information for the item
    page.querySelector('.detailPagePrimaryContainer').classList.add('detailRibbon');
    renderName(item, page.querySelector('.nameContainer'), params.context);
    renderDetails(page, item, apiClient, params.context);
    renderTrackSelections(page, instance, item);

    renderSeriesTimerEditor(page, item, apiClient, user);
    renderTimerEditor(page, item, apiClient, user);
    setInitialCollapsibleState(page, item, apiClient, params.context, user);
    const canPlay = reloadPlayButtons(page, item);

    setTrailerButtonVisibility(page, item);

    if (item.Type !== 'Program' || canPlay) {
        hideAll(page, 'mainDetailButtons', true);
    } else {
        hideAll(page, 'mainDetailButtons');
    }

    showRecordingFields(instance, page, item, user);
    const groupedVersions = (item.MediaSources || []).filter(function (g) {
        return g.Type == 'Grouping';
    });

    if (user.Policy.IsAdministrator && groupedVersions.length) {
        page.querySelector('.btnSplitVersions').classList.remove('hide');
    } else {
        page.querySelector('.btnSplitVersions').classList.add('hide');
    }

    if (itemContextMenu.getCommands(getContextMenuOptions(item, user)).length) {
        hideAll(page, 'btnMoreCommands', true);
    } else {
        hideAll(page, 'btnMoreCommands');
    }

    const itemBirthday = page.querySelector('#itemBirthday');

    if (item.Type == 'Person' && item.PremiereDate) {
        try {
            const birthday = datetime.parseISO8601Date(item.PremiereDate, true);
            const durationSinceBorn = intervalToDuration({ start: birthday, end: Date.now() });
            itemBirthday.classList.remove('hide');
            if (item.EndDate) {
                itemBirthday.innerHTML = globalize.translate('BirthDateValue', birthday.toLocaleDateString());
            } else {
                itemBirthday.innerHTML = `${globalize.translate('BirthDateValue', birthday.toLocaleDateString())} ${globalize.translate('AgeValue', durationSinceBorn.years)}`;
            }
        } catch (err) {
            console.error(err);
            itemBirthday.classList.add('hide');
        }
    } else {
        itemBirthday.classList.add('hide');
    }

    const itemDeathDate = page.querySelector('#itemDeathDate');

    if (item.Type == 'Person' && item.EndDate) {
        try {
            const deathday = datetime.parseISO8601Date(item.EndDate, true);
            itemDeathDate.classList.remove('hide');
            if (item.PremiereDate) {
                const birthday = datetime.parseISO8601Date(item.PremiereDate, true);
                const durationSinceBorn = intervalToDuration({ start: birthday, end: deathday });

                itemDeathDate.innerHTML = `${globalize.translate('DeathDateValue', deathday.toLocaleDateString())} ${globalize.translate('AgeValue', durationSinceBorn.years)}`;
            } else {
                itemDeathDate.innerHTML = globalize.translate('DeathDateValue', deathday.toLocaleDateString());
            }
        } catch (err) {
            console.error(err);
            itemDeathDate.classList.add('hide');
        }
    } else {
        itemDeathDate.classList.add('hide');
    }

    const itemBirthLocation = page.querySelector('#itemBirthLocation');

    if (item.Type == 'Person' && item.ProductionLocations && item.ProductionLocations.length) {
        let location = item.ProductionLocations[0];
        if (!layoutManager.tv && appHost.supports('externallinks')) {
            location = `<a is="emby-linkbutton" class="button-link textlink" target="_blank" href="https://www.openstreetmap.org/search?query=${encodeURIComponent(location)}">${escapeHtml(location)}</a>`;
        } else {
            location = escapeHtml(location);
        }
        itemBirthLocation.classList.remove('hide');
        itemBirthLocation.innerHTML = globalize.translate('BirthPlaceValue', location);
    } else {
        itemBirthLocation.classList.add('hide');
    }

    setPeopleHeader(page, item);
    loading.hide();

    if (item.Type === 'Book' && item.CanDownload && appHost.supports('filedownload')) {
        hideAll(page, 'btnDownload', true);
    }

    autoFocus(page);
}