EzDevInfo.com

Datejs

A JavaScript Date and Time Library Datejs - An open-source JavaScript Date Library datejs (date.js) is an open-source javascript date library released under the mit license.

Datejs and d3.js conflict with transition

I've been using both D3.js and date.js (http://www.datejs.com/) and find out that the transition() method in D3 doesn't work. - that is I can't make any animations with D3 when date.js is also included in the same HTML file.

I suppose it should be scope or namespace conflict, but I don't know how to fix it. All D3 codes are in one global variable, but it doesn't help. Anyone have solutions for this, except for not using one of these. :-)?


Source: (StackOverflow)

Work with a time span in Javascript

Using Date.js already, but can also use another library if necessary.

Not sure what is the best way to work with time deltas. Specifically, I want to display the time that has elapsed between now and a past date-time.

So I need to do something like this:

var elapsed_time = new Date() - pastDate;
pastDate.toString('days-hours-minutes-seconds');

Gotten it to mostly work using Date.js, but the problem is now I'm working with a Date object and not a timespan, so what should be an 23 hour time span is instead 23 hours after the Date's very first time:

var result = (new Date()) - past_date;
"result" is the number (probably milliseconds): 15452732
var result = (new Date() - past_date
"result" is a date from 1969: Wed Dec 31 1969 23:17:32

What I need is:

0 days 23 hours 17 minutes and 32 seconds

Any ideas?


Source: (StackOverflow)

Advertisements

jQuery UI Datepicker and datejs

I want to have a datepicker where you can also just type basically I want to have the jQuery UI Datepicker and datejs in one. I want to type "tomorrow" and I want it to select the right day. I want to be able to type "saturday" and it actually getting the date right.


Source: (StackOverflow)

Datejs - Problem with 12:00 pm

I really have no idea what I'm doing wrong here. I can't get Datejs to properly parse "12:00 pm" however, it seems to work fine on other dates. Below is a clip from the Firefox debugger:

enter image description here


Source: (StackOverflow)

Comparing two dates with javascript or datejs (date difference)

I am trying to compare two dates which are in Finnish time form like this: dd.mm.YYYY or d.m.YYYY or dd.m.YYYY or d.mm.YYYY.

I am having a hard time finding out how to do this, my current code won't work.

<script src="inc/date-fi-FI.js" type="text/javascript"></script>
<script type="text/javascript">
    function parseDate() {
        var date = $('#date').val();
        var parsedDate = Date.parse(date);
        alert('Parsed date: '+parsedDate);
    }
    function jämförMedIdag (datum) {
    if (datum == null || datum == "") {
        alert('Inget datum!');
        return;
    }
    /*resultat = Date.compare(Datum1,Datum2);
    alert(resultat); */
    var datum = Date.parse(datum);
    var dagar = datum.getDate();
    var månader = datum.getMonth();
    var år = datum.getYear();
    var nyttDatum = new Date();
    nyttDatum.setFullYear(år,månader,dagar);
    var idag = new Date();

    if(nyttDatum>idag) {
        var svar = nyttDatum - idag;
        svar = svar.toString("dd.MM.yyyy");
        alert(svar);
        return(svar);
    } else {
        var svar = idag - nyttDatum;
        svar = svar.toString("dd.MM.yyyy");
        alert(svar);
        return(svar);
    }
}    
</script>

This code will try to calculate the difference between two dates, one of them being today. No success lolz.

Thanks in advance!

My final code (thanks RobG!):

function dateDiff(a,b,format) {
    var milliseconds = toDate(a) - toDate(b);
    var days = milliseconds / 86400000;
    var hours = milliseconds / 3600000;
    var weeks = milliseconds / 604800000;
    var months = milliseconds / 2628000000;
    var years = milliseconds / 31557600000;
    if (format == "h") {
        return Math.round(hours);
    }
    if (format == "d") {
        return Math.round(days);
    }
    if (format == "w") {
        return Math.round(weeks);
    }
    if (format == "m") {
        return Math.round(months);
    }
    if (format == "y") {
        return Math.round(years);
    }
}

It is not fully accurate, but very close. I ended up adding some addons to it to calculate in day week month year or hour, anyone can freely copy and use this code.


Source: (StackOverflow)

Parse ONLY a time string with DateJS

I'm using the excellent (but large) DateJS library to handle dates and times in my webapp. I just came across something that I'm not sure how to handle.

I want my users to be able to enter Time strings only, without a date, but they should be able to enter it in any manner they please. For instance:

  • 5:00 pm
  • 17:00
  • 5:00pm
  • 5:00p
  • 5p
  • etc.

Using Date.parse(value) converts these strings into a full date, which is exactly what I want. However, it also allows the user to enter any other part of a date string, such as:

  • sat 5pm
  • 1/1/2010 5pm
  • etc.

I'm trying to use DateJS to validate an input field for a time value. Something like:

function validateTime(value) {
    return Date.parse(value) !== null;
}

Is there a way to use DateJS features to solve this? There are other SO questions that provide solutions, but if DateJS has a way to do this, I don't really want to add more custom code to my app to do this.


Source: (StackOverflow)

Date.js vs Moment.js (and server-side formatting)

I've been using Date.js in my project and recently read a post that moment.js was superior.

However, I'm having trouble believing that it is simply due to the fact that it can't parse input like "5 days from now" to an n actual date.

My personal desire/requirements are that

  1. I can take a variety of inputs (text-fields) and submit them as properly formatted dates.
  2. I can take properly formatted dates and output them as friendly (or just parse them differently).

Date.js does both. Moment.js seems to only do #2...

Am I missing something, or am I cool to use Date.js still?

Additionally...for my rails project. Is it better to format things server-side or client side? ie. I have a few things I'd like to format based on the relative date condition. (Like add a class if it's 10 days from now, or >0 days past now)...pros/cons of client/server side date parsing/manipulation?


Source: (StackOverflow)

datejs parsing some month is not working

I'm using date-fr-FR.js

When I'm doing this

Date.parse("5 juillet 2012")

it's returning null

But when I do this

Date.parse("5 juil. 2012")

it's returning the right date, someone have an idea ? Thanks


Source: (StackOverflow)

How to correctly compare years within MM-dd-yyyy strings?

I'm using date.js to apply conditional formatting to a data grid. The data is parsed from a javascript array. All of my conditions are working correctly, except for this one:

if (val < today && val > '01-01-2000')

val is a string in MM-dd-yyyy format that I can't change. So I used date.js to convert today's date to a string in MM-dd-yyyy format and make the comparison. The problem is that 01-17-2014 is seen as less than 04-08-2013 - since it is comparing strings.

What's the best way around this?

I'd like to make it simple, which is why I converted to strings in the first place, but I'm not sure how to get around the year issue.

Thanks for any help!

var today = new Date.today().toString("MM-dd-yyyy");
var tomorrow = new Date.today().addDays(1).toString("MM-dd-yyyy");
var upcoming = new Date.today().addDays(7).toString("MM-dd-yyyy");

function eXcell_edncl(cell) {
    this.base = eXcell_edn;
    this.base(cell);
    this.setValue = function(val) {
        if (val.indexOf('ACT') >= 0) this.cell.style.backgroundColor="lightgreen";
        else if (val.indexOf('PV') >= 0) this.cell.style.backgroundColor="lightgreen", this.cell.style.fontSize="20px";
        else if (val.indexOf('YES') >= 0) this.cell.style.backgroundColor="lightgreen", this.cell.style.fontSize="20px";
        else if (val < today && val > '01-01-2000') this.cell.style.backgroundColor="red";
        else if (val == today) this.cell.style.backgroundColor="orange";
        else if (val == tomorrow) this.cell.style.backgroundColor="yellow";
        else if (val > tomorrow && val <= upcoming) this.cell.style.backgroundColor="lightyellow";
        else this.cell.style.backgroundColor="";
        this.cell.innerHTML = this.grid._aplNF(val, this.cell._cellIndex);
    }
}

Source: (StackOverflow)

Date and time without timestamp in Javascript

In Javascript I need to work with the concepts of date, time and "date and time " without referring to a particular point in time. This is exactly the same semantics that joda time's LocalDate and LocalTime provide in Java. I've been briefly looking at Date.js and moment.js, but both libraries seem to build on the Date object, which represents a point in time. Is there any javascript library that provides what I need?

Use case:

There is a model entity -a coupon- which has an expiration date (joda time's LocalDate). I want to compare that date with today's date, so I need a representation of today's date (actually a string in yyyy-mm-dd format would do). I know that today's date, and hence the result of the comparison too, will depend on the timezone settings of the browser's but that's not a problem.


Source: (StackOverflow)

how to use filament's daterangepicker with new jquery?

I downloaded the daterangepicker available here : filament group

I am using jQuery 1.4.x version in my page, and all other plugins I am using are supported only on latest version of jQuery. The daterangepicker tool fails because it is using date.js (which uses a very old jQuery).

If I use datepicker, all other plugins and functionality of rest of the plugins I am using are lost.

I went through filament group's comments and found this :

@ Mckensy: We made sure to use “jQuery” instead of $ to prevent such collisions but it appears the date.js library uses $, which is probably causing your conflict. Maybe you could try replacing their $ variables with something else.

he means that noConflict mode doesn't work and only way is to change date.js.

Now can someone please tell me how to do what he says ??


Source: (StackOverflow)

Timeago + DateJS = NaN

I'm trying to use timeago (source), with datejs, and it's not working. Here's some sample code I'd expect to work (given that timeago and datejs are loaded):

>>> d = new Date()
Mon Jun 21 2010 13:24:37 GMT-0400 (EST) { _orient=1, more...}
>>> d.toISOString()          // datejs.toISOString
"2010-06-21T17:24:37.501Z"   // this is a valid ISO8601 string, I believe
>>> $.timeago(d.toISOString()) // this should work
"NaN years ago"

I'd be much obliged for any input as to why this may be failing, and how one could go about fixing or circumventing this problem.

Thank you.

Brian


Source: (StackOverflow)

date.js Parse method overrides Javascript Parse method

I'm including the date.js library in my site because I need its functionality.

I have just realized, though, that the standard Javascript parse() method is overwritten by it.

I'm trying to build a line chart in Highcharts, and the data series wants the first element to be be in milliseconds (their demos show them using the Date.UTC() method to achieve this, but my data is returned in a different format).

Short of doing a bunch of string manipulation to put my data into a format that Date.UTC will recognize, is there another way of getting the standard Javascript parse() functionality while date.js is loaded?


Source: (StackOverflow)

addDay() function returns wrong value in Data.js

I am using Date.js in my web app, when i subtract one day from "Mon Oct 8 00:00:00 UTC-0300 2012" , it is returning "oct 6" instead of "oct 7"

Here is my code:

var startTime = new Date(2012, 9, 8);
var beforeStare = startTime.clone().addDays(-1);

enter image description here

Why this is happening ? how to fix this ?

and also i tried this new Date(2012,9,7); it returns

oct 6 23:00:00 UTC-0300 2012

Note: i am using the Asuncion(UTC-04:00) TimeZone

JSFiddler


Source: (StackOverflow)

If I have a time like 1325982833403 in JavaScript, how do I convert it to a datejs value?

The JavaScript library I'm using represents user login times as long integers:

1325982833403

How do I convert this to a DateTime ('MM/dd/yyyy hh:mm tt') value that the datejs library would understand?


Source: (StackOverflow)