Comparing version 0.3.13 to 0.3.14
@@ -95,6 +95,23 @@ js-joda Cheat sheet | ||
// TODO | ||
// get week of week based year | ||
dt.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 8 | ||
### Get weeks of week based year, get year quarters and the day of quarter | ||
// get week of week based year as defined by ISO 8601 with a monday based week | ||
d.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 51 | ||
d.isoWeekOfWeekyear(); // 51, is the same as above | ||
d.isoWeekyear(); // 2016 | ||
LocalDate.of(2017,1,1).isoWeekOfWeekyear(); // 52 | ||
LocalDate.of(2017,1,1).isoWeekyear(); // 2016 | ||
// set the date to week 52 of week based year with the same day of week | ||
d.with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 52); // 2016-12-31 | ||
// get the quarter of the year | ||
d.get(IsoFields.QUARTER_OF_YEAR); // 4 | ||
d.get(IsoFields.DAY_OF_QUARTER); // 85 | ||
// set the date to 15th day of the third quarter | ||
d.with(IsoFields.QUARTER_OF_YEAR, 3).with(IsoFields.DAY_OF_QUARTER, 15) // 2016-07-15 | ||
``` | ||
@@ -158,4 +175,4 @@ | ||
// set the ALIGNED_WEEK_OF_YEAR to 51 | ||
d.with(ChronoField.ALIGNED_WEEK_OF_YEAR, 51) // 2016-12-17 | ||
// set the WEEK_OF_WEEK_BASED_YEAR to 52 | ||
d.with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 52) // 2016-12-31 | ||
@@ -229,14 +246,12 @@ // set by a TemporalAdjuster lastDayOfMonth | ||
// TODO milestone 1 add Basic ZoneDateTime and add a Converterhelper | ||
// obtain a LocalDate from an Instant | ||
// Instant.now().atZone(ZoneId.systemDefault()).toLocalDate() | ||
// obtain a LocalDate from a JavaScript Date | ||
// var javascriptDate = new Date(); | ||
// Instant.ofEpochMilli(javascriptDate.getTime()).atZone(ZoneId.systemDefault()).toLocalDate() | ||
// the manual way | ||
var d = LocalDate.ofInstant(Instant.ofEpochMilli(new Date().getTime())); | ||
// obtaim a LocalDate from a moment | ||
// var moment = moment(); | ||
// Instant.ofEpochMilli(moment.toDate().getTime()).atZone(ZoneId.systemDefault()).toLocalDate() | ||
// the recommended way with the javascript temporal | ||
d = LocalDate.from(nativeJs(new Date())); | ||
// converting from a moment is workings the same way | ||
d = LocalDate.from(nativeJs(moment())); | ||
``` | ||
@@ -406,3 +421,19 @@ | ||
### Convert from a javascript Date or moment | ||
```javascript | ||
// obtain a LocalTime instance from a JavaScript Date | ||
// the manual way | ||
var t = LocalTime.ofInstant(Instant.ofEpochMilli(new Date().getTime())); | ||
// the recommended way with the javascript temporal | ||
t = LocalTime.from(nativeJs(new Date())); | ||
// converting from a moment is workings the same way | ||
d = LocalTime.from(nativeJs(moment())); | ||
``` | ||
## LocalDateTime | ||
@@ -476,5 +507,5 @@ | ||
// TODO | ||
// get week of week based year | ||
// dt.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 8 | ||
dt.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); // 8 | ||
dt.toLocalDate().isoWeekOfWeekyear(); | ||
@@ -629,2 +660,19 @@ // get other time based fields | ||
### Convert from a javascript Date or moment | ||
```javascript | ||
// obtain a LocalTime instance from a JavaScript Date | ||
// the manual way | ||
var t = LocalDateTime.ofInstant(Instant.ofEpochMilli(new Date().getTime())); | ||
// the recommended way with the javascript temporal | ||
t = LocalDateTime.from(nativeJs(new Date())); | ||
// converting from a moment is workings the same way | ||
d = LocalDateTime.from(nativeJs(moment())); | ||
``` | ||
## Period | ||
@@ -713,3 +761,2 @@ | ||
IsoFields implements fields and units for an ISO week based year. | ||
// TODO temporal/IsoFields is not yet migrated to js-joda, check org.threeten.bp.temporal.IsoFields for now. | ||
@@ -716,0 +763,0 @@ ### Custom formatter and queries |
{ | ||
"name": "js-joda", | ||
"version": "0.3.13", | ||
"version": "0.3.14", | ||
"description": "a date and time library for javascript", | ||
@@ -29,11 +29,11 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "^6.6.4", | ||
"babel-core": "^6.6.4", | ||
"babel-cli": "^6.6.5", | ||
"babel-core": "^6.7.0", | ||
"babel-loader": "^6.2.4", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.8", | ||
"esdoc": "^0.4.5", | ||
"esdoc": "^0.4.6", | ||
"isparta": "^4.0.0", | ||
"karma": "^0.13.21", | ||
"karma": "^0.13.22", | ||
"karma-chai-plugins": "^0.7.0", | ||
@@ -40,0 +40,0 @@ "karma-chrome-launcher": "^0.2.2", |
@@ -20,2 +20,3 @@ /* | ||
import {_init as ChronoUnitInit} from './temporal/ChronoUnit'; | ||
import {_init as IsoFieldsInit} from './temporal/IsoFields'; | ||
import {_init as TemporalQueriesInit} from './temporal/TemporalQueries'; | ||
@@ -38,2 +39,3 @@ | ||
ChronoFieldInit(); | ||
IsoFieldsInit(); | ||
TemporalQueriesInit(); | ||
@@ -40,0 +42,0 @@ DayOfWeekInit(); |
@@ -19,5 +19,6 @@ /** | ||
export {nativeJs} from './temporal/NativeJsTemporal' | ||
export {nativeJs} from './temporal/NativeJsTemporal'; | ||
export {ChronoField} from './temporal/ChronoField'; | ||
export {ChronoUnit} from './temporal/ChronoUnit'; | ||
export {IsoFields} from './temporal/IsoFields'; | ||
export {TemporalAdjusters} from './temporal/TemporalAdjusters'; | ||
@@ -24,0 +25,0 @@ export {TemporalQueries} from './temporal/TemporalQueries'; |
@@ -13,3 +13,3 @@ /* | ||
import {MathUtil} from '../MathUtil'; | ||
import {ZoneOffset} from '../ZoneOffset'; | ||
import {ZoneId} from '../ZoneId'; | ||
@@ -29,5 +29,7 @@ import {ChronoField} from './ChronoField'; | ||
* @param {!(Date|moment)} date - a javascript Date or a moment instance | ||
* @param {ZoneId} [zone=ZoneId.systemDefault()] - the zone of the temporal, defaults to ZoneId.systemDefault() | ||
*/ | ||
constructor(date){ | ||
constructor(date, zone=ZoneId.systemDefault()){ | ||
super(); | ||
this._zone = zone; | ||
if(date instanceof Date) { | ||
@@ -52,7 +54,7 @@ this._epochMilli = date.getTime(); | ||
if (query === TemporalQueries.localDate()) { | ||
return LocalDate.ofInstant(Instant.ofEpochMilli(this._epochMilli), ZoneOffset.UTC); | ||
return LocalDate.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone); | ||
} else if(query === TemporalQueries.localTime()){ | ||
return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), ZoneOffset.UTC); | ||
return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone); | ||
} else if(query === TemporalQueries.zone()){ | ||
return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), ZoneOffset.UTC); | ||
return LocalTime.ofInstant(Instant.ofEpochMilli(this._epochMilli), this._zone); | ||
} | ||
@@ -90,5 +92,10 @@ return super.query(query); | ||
export function nativeJs(date){ | ||
return new NativeJsTemporal(date); | ||
/** | ||
* | ||
* @param {!(Date|moment)} date - a javascript Date or a moment instance | ||
* @param {ZoneId} [zone=ZoneId.systemDefault()] - the zone of the temporal, defaults to ZoneId.systemDefault() | ||
* @returns {NativeJsTemporal} | ||
*/ | ||
export function nativeJs(date, zone){ | ||
return new NativeJsTemporal(date, zone); | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2341290
64
25535