Skip to content

Commit

Permalink
Merge pull request #483 from iamkun/dev
Browse files Browse the repository at this point in the history
D2M
  • Loading branch information
andrewhood125ruhuc committed May 9, 2026
2 parents e11df8b + e980f4d commit 7935dfa
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ coverage
/locale
/plugin
dayjs.min.js
/esm

#dev
demo.js
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package-lock.json
coverage

# dev
src
test
build
.babelrc
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script:
- codecov
after_success:
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
npx travis-deploy-once && npm run build && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && npm run test:sauce;
npx travis-deploy-once && npm run build && npm run babel && npm install -g @semantic-release/changelog @semantic-release/git semantic-release && semantic-release && npm run test:sauce;
fi
branches:
except:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Our open source community strives to be nice, welcoming and professional. Instan
* Before submitting a bug report, search the issues for similar tickets. Your issue may have already been discussed and resolved.
* Feel free to add a comment to an existing issue, even if it's closed.
* Be thorough in your title and report, don't leave out important details.
* English please.
* English, please.

## Tests

Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "2KB immutable date time library alternative to Moment.js with the same modern API ",
"main": "dayjs.min.js",
"types": "index.d.ts",
"module": "./src/index.js",
"module": "./esm/index.js",
"scripts": {
"test": "TZ=Pacific/Auckland npm run test-tz && TZ=Europe/London npm run test-tz && npm run test-tz && jest",
"test-tz": "jest test/timezone.test --coverage=false",
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
"babel": "cross-env BABEL_ENV=build babel src --out-dir esm --copy-files",
"build": "cross-env BABEL_ENV=build node build && npm run size",
"sauce": "npx karma start karma.sauce.conf.js",
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2 && npm run sauce -- 3",
Expand Down Expand Up @@ -40,9 +41,14 @@
{
"path": "@semantic-release/changelog"
},
["@semantic-release/git", {
"assets": ["CHANGELOG.md"]
}]
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
]
}
]
]
},
"keywords": [
Expand Down
43 changes: 43 additions & 0 deletions src/locale/en-gb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import dayjs from 'dayjs'

const locale = {
name: 'en-gb',
weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
weekdaysShort: 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
weekdaysMin: 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
monthsShort: 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
weekStart: 1,
relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
},
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd, D MMMM YYYY HH:mm'
},
ordinal: (n) => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
return `[${n}${(s[(v - 20) % 10] || s[v] || s[0])}]`
}
}

dayjs.locale(locale, null, true)

export default locale
3 changes: 2 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ const parseFormattedInput = (input, format) => {
minutes || 0, seconds || 0, milliseconds || 0
) + (zone.offset * 60 * 1000))
}
const now = new Date()
return new Date(
year, month - 1, day,
year || now.getFullYear(), month - 1 || now.getMonth(), day || now.getDate(),
hours || 0, minutes || 0, seconds || 0, milliseconds || 0
)
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions test/locale/keys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ it('Locale keys', () => {

expect(months).toEqual(expect.any(Array))
// function pass date return string or number or null
expect(ordinal(1)).toEqual(expect.anything())
expect(ordinal(3)).toEqual(expect.anything())
for (let i = 1; i <= 31; i += 1) {
expect(ordinal(i)).toEqual(expect.anything())
}
expect(dayjs().locale(name).$locale().name).toBe(name)
if (formats) {
expect(Object.keys(formats).sort()).toEqual(['L', 'LL', 'LLL', 'LLLL', 'LT', 'LTS'].sort())
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ it('timezone with no hour', () => {
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('parse just hh:mm)', () => {
const input = '12:00'
const format = 'hh:mm'
expect(dayjs(input, format).valueOf()).toBe(moment(input, format).valueOf())
})

it('fails with an invalid format', () => {
const input = '2018-05-02 12:00 PM'
const format = 'C'
Expand Down

0 comments on commit 7935dfa

Please sign in to comment.