Giter VIP home page Giter VIP logo

date.format's People

Contributors

blackwicked avatar heathdutton avatar jacwright avatar kkevindev avatar laci87 avatar matveifisenko avatar sirmadman avatar spasa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

date.format's Issues

feature request: Quarter

Jacob,

Will you add this to date.format.js for Quarter? If this code is not correct, please let me know what's wrong with it.

// Quarter
Q: function() { var d = new Date(); return Math.floor((d.getMonth() + 3) / 3); },

Thanks!
Tim Allums

Week calculation issue date.format('W')

I realized that something is wrong with the week calculation when I received constantly incorrect results. After some digging I found out that it must be an ISO implementation bug.

ISO 8601 states that week 1 is the week with the first Thursday of that year.

Use case:

Sat Aug 16 2014 02:00:00 GMT+0200 (CEST)

Result:

Week number: 34

Expected:

Week number: 33

Solution:

I found this article, in which the code in Date.getWeek() section seems to have a working solution.

http://techblog.procurios.nl/k/news/view/33796/14863/calculate-iso-8601-week-and-year-in-javascript.html

Fails when year is leap

Hi, hi.
Display wrong week number with W for this use cases:

currentWeekNumber("March 24, 2015")
//=> 13
currentWeekNumber("03/24/2016")
//=> 13, must be 12

currentWeekNumber("August 07, 2015")
//=> 32, that's okey
currentWeekNumber("02/16/2015")
//=> 7, nope, must be 8

Any ideas? I try to beat it from few hours, but.. I'm not lucky guy.

This is little extended code:

module.exports = function currentWeekNumber(date) {
  var instance, inst;
  if (date && typeof date === 'string' && date !== '') {
    instance = new Date(date);
  } else {
    instance = new Date();
  }
  inst = new Date(instance.getFullYear(), 0, 1);
  return Math.ceil((((instance - inst) / 86400000) + inst.getDay() + 1) / 7);
}

Before I found this repo, I use current-day-number and was near to truth

var currentDayNumber = require('current-day-number');

module.exports = function currentWeekNumber(date) {
  date = date || "";
  return ((currentDayNumber(date) / 7) +1.24) | 0;
};

Really... I can't realize why hole this shit is happening. :D

dateformat does't work on latest firefox.

for example. I am currently in EDT.

the utc timestamp = 1394355600000
d = new Date(utc) gives me
Date 2014-03-09T09:00:00.000Z

d.format('T') gives EST which is wrong.

d.format('T') should give EDT.

format("z") seems to have issues with timezones

In Chrome's console:

new Date(1534545439635);
Sat Aug 18 2018 00:37:19 GMT+0200 (Central European Summer Time)

new Date(1534545439635).format("z");
"229"

The same day but later:

new Date(1534588427903)
Sat Aug 18 2018 12:33:47 GMT+0200 (Central European Summer Time)

new Date(1534588427903).format("z");
"230"

The timestamp at 00:37:19 returns "229" but the timestamp of the same day at 12:33:47 returns "230"

Note: Central European Summer Time is GMT +02:00 ;)

var d defined twice

Hi Jan,

I just noticed the variable d is defined twice:
d: function() { var d = this.getDate(); return (d < 10 ? '0' : '') + d; },
and
z: function() { var d = new Date(this.getFullYear(),0,1); return Math.ceil((this - d) / 86400000); },

I think the second one should beȘ
z: function() { var z = new Date(this.getFullYear(),0,1); return Math.ceil((this - z) / 86400000); },

Time Zone For Half Hour

Using format charackter "O", should show difference to Greenwich time (GMT) in hours (I think this is RFC 822 time zone). It is working fine with integer hours. For time zones with half an hour differences (eg. Kabul Afganistan) instead of showing +0430 it is showing +04.500

Publish to npm?

It'd be great to be able to npm install this module and require it.

Issue with displaying months using "M" & "F"

Hi Guys

When using M I get this:
Uncaught TypeError: Cannot read property 'shortMonths' of undefined date.format.js:23

When using F I get this:
Uncaught TypeError: Cannot read property 'longMonths' of undefined date.format.js:21

"m" and "n" appear to work fine though!

Any ideas?

format("z") should be 0-based

PHP uses zero-based numbering for "z" in date formatting and returns values from 0 - 365. This library returns values from 1 - 366.
In my opinion, to fully mimic PHP, the function should end with a subtraction of 1:

(linebreaks added for readability)

z: function () { 
  var d = new Date(this.getFullYear(), 0, 1);
  return Math.ceil((this - d) / 86400000) - 1
},

Or was there a motivation to not used zero-based numbering here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.