Coder Social home page Coder Social logo

moment-parseformat's Introduction

moment.parseFormat – a moment.js plugin

Test

A moment.js plugin to extract the format of a date/time string

Installation

Load via script tag

<script src="moment.js"></script>
<script src="moment.parseFormat.js"></script>

Install using npm for node.js:

npm install --save moment-parseformat

Browser Usage

var format = moment.parseFormat('Thursday, February 6th, 2014 9:20pm'/* , options */);
// dddd, MMMM Do, YYYY h:mma
moment().format(format); // format

Node / CommonJS Usage

var moment  = require 'moment'
var parseFormat = require('moment-parseformat')

var format = parseFormat('Thursday, February 6th, 2014 9:20pm'/* , options */);
// dddd, MMMM Do, YYYY h:mma
moment().format(format); // format

Options

Options can be passed as 2nd parameter

preferredOrder

Type: Object or String

parseFormat tries to figure out the the order of day/month/year by itself if it finds 3 numbers separated by ., - or /. But if it can't, it will fallback to preferredOrder, which can either be set as an object to differentiate by separator, or as a simple string.

Default value:

preferredOrder: {
  '/': 'MDY',
  '.': 'DMY',
  '-': 'YMD'
}

Usage

parseFormat('10.10.2010', {preferredOrder: 'DMY'});
// ☛ DD.MM.YYYY
parseFormat('10.10.2010', {preferredOrder: 'MDY'});
// ☛ MM.DD.YYYY
parseFormat('10.10.2010', {preferredOrder: {
  '/': 'MDY',
  '.': 'DMY',
  '-': 'YMD'
}});
// ☛ MM.DD.YYYY
parseFormat('10/10/2010', {preferredOrder: {
  '/': 'MDY',
  '.': 'DMY',
  '-': 'YMD'
}});
// ☛ DD/MM/YYYY

Fine Print

The moment.parseFormat Plugin have been authored by Gregor Martynus, proud member of the Hoodie Community.

License: MIT

moment-parseformat's People

Contributors

angcap avatar gr2m avatar greenkeeper[bot] avatar greenkeeperio-bot avatar harsimranb avatar hillmanov avatar idanb11 avatar jedwards1211 avatar jefffriesen avatar larrybattle avatar mgd134 avatar ncronquist avatar theoludwig avatar zoepage 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

moment-parseformat's Issues

2014-01-10 20:00:15 → YYYY-MM-DD H:mm:D

moment.parseFormat('2014-01-10 20:00:15') parsed to YYYY-MM-DD H:mm:D, I expected: <YYYY-MM-DD H:mm:DD>

AFAIKT there are always two digets for seconds. Also, should hours get formated with two digets as well?

PS: Overall - awesome library idea :)

Thursday at 9:20pm

moment.parseFormat('Thursday at 9:20pm') parsed to dddd [at] h:mma, I expected: <please fill in>

3/15 → D/YY

moment.parseFormat('3/15') parsed to D/YY, I expected: M/D

Although D/YY is a valid interpretation, it's not the most intuitive one.

Library cannot be minified

This library cannot be minified and concatenated with the rest of our dependencies, but when delivered unminified all works well.

SUNNYVALE → dddNYVALE

Obviously this isn't a date, because I'm using parseFormat to help look for dates and times in CSV data.
moment.parseFormat('SUNNYVALE') parsed to dddNYVALE, I expected: SUNNYVALE (or null)

I think we should exclude any month/day name or abbrev matches that have adjacent letters.

Should default to leading 0's

So I was looking through the regex's and realized that it will only parse timestamps as having a leading 0 if there's an explicit leading 0.

/0\d:\d{2}:\d{2}/

Now this means that it will correctly parse something like 01:33:47 as HH:mm:ss
However once it goes above that to 12:33:47,
it will parse that out as H:mm:ss which is technically correct, as at this point there's no way to know if the timestamp would or would not have a leading 0.

However, I would say that assuming a leading 0 in these caes should be the default, as that is more commonly used with timestamps, and a not leading zero should be the one that is explicitly set,
ie any timestamp like 12:34:56 parses out as HH:mm:ss and the only way to get something as H:mm:ss would be to have a match with something like 1:23:45.

format problem

Thursday, February 6th, 2014 9:20pm this format is recognized as invalid by moment.js

15/05/1987 → MM/DD/YYYY

moment.parseFormat('15/05/1987') parsed to MM/DD/YYYY, I expected: <please fill in>

The correct would be DD/MM/YYYY!!

An in-range update of semantic-release is breaking the build 🚨

Version 15.9.6 of semantic-release was just published.

Branch Build failing 🚨
Dependency semantic-release
Current Version 15.9.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).
  • coverage/coveralls: First build on greenkeeper/semantic-release-15.9.6 at 99.259% (Details).

Release Notes v15.9.6

15.9.6 (2018-08-08)

Bug Fixes

  • do not convert ssh repositoryUrl to https (b895231)
Commits

The new version differs by 3 commits.

  • b895231 fix: do not convert ssh repositoryUrl to https
  • 8b8e40c docs(plugins): add semantic-release-firefox
  • 06695a1 chore(package): update xo to version 0.22.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

today → today

moment.parseFormat('today') parsed to today, I expected: moment()

3-1-81 → YY-M-D

moment.parseFormat('3-1-81') parsed to YY-M-D, I expected: M-D-YY

Looks like this is still a problem. I checked 9-17-80, and it worked, but I'm guessing that was because of the 17.

31/12/2013 → MM/DD/YYYY

moment.parseFormat('31/12/2013') parsed to MM/DD/YYYY, I expected: DD/MM/YYYY.

Other test cases:

moment.parseFormat('12/31/2013') parsed to MM/DD/YYYY => Correct
moment.parseFormat('31-12-2013') parsed to DD-MM-YYYY => Correct
moment.parseFormat('12-31-2013') parsed to MM-DD-YYYY => Correct

Doesn't work in the browser when not using require js

@gr2m thanks for this great tool ! however, it does not work in the browser... 😢
i did `bower install moment-parse-format --save'
and the console would show require is not defined.

Simple way to fix it is to put the whole thing in an iife

Parsing fractional seconds

Hi,

We really like your library. Thanks for the work. We've noticed that the library doesn't produce the correct output for fractional seconds until the input gets all the way to milliseconds. I have modified the code in my fork so that it will parse tenths and hundredths of a second properly. Would you like me to submit a pull request?

Mike

Should be able to parse ISO-8601 Format

There is currently only support for the following:

2014-02-02T10:11:58+00:00 → YYYY-MM-DDTHH:mm:ssZ

This does not have support for negative offset, or MS.
Forthcoming PR with support for the following:

2014-09-04T01:20:28.888+02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ
2014-09-04T01:20:28.888-02:00 → YYYY-MM-DDTHH:mm:ss.SSSZ
2014-02-02T10:11:58.888Z → YYYY-MM-DDTHH:mm:ss.SSSZ

running this produce error: var format = parseFormat(1397418578);

var format = parseFormat(1397418578);

c:\Users\Idanb11\Work\workspace\node_modules\moment-parseformat\lib\parseformat.js:79
  format = format.replace(regexUnixMillisecondTimestamp, 'x')
                  ^

TypeError: format.replace is not a function
    at parseFormat (c:\Users\Idanb11\Work\workspace\node_modules\moment-parseformat\lib\parseformat.js:79:19)
    at Object.<anonymous> (c:\Users\Idanb11\Work\workspace\server.js:5:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

7/12/65 → M/D/YY

moment.parseFormat('7/12/65') parsed the year to 2065, I expected: 1965

An in-range update of semantic-release is breaking the build 🚨

Version 15.4.3 of semantic-release was just published.

Branch Build failing 🚨
Dependency semantic-release
Current Version 15.4.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
  • coverage/coveralls First build on greenkeeper/semantic-release-15.4.3 at 99.259% Details

Release Notes v15.4.3

15.4.3 (2018-05-21)

Bug Fixes

  • package: update marked to version 0.4.0 (a387c04)
Commits

The new version differs by 5 commits.

  • a387c04 fix(package): update marked to version 0.4.0
  • 228451b docs: fix typo
  • 3503407 docs: clarify which commit types trigger a release
  • 5025fca docs: fix FAQ heading level
  • 6693080 style: fix table indentation

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.