Skip to content

Commit

Permalink
Merge pull request #397 from livingspec/RDBC-760
Browse files Browse the repository at this point in the history
RDBC-760 add setter for DateUtil in DocumentConventions
  • Loading branch information
ml054 authored Sep 28, 2023
2 parents 299d778 + fd5218a commit fc5e149
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Documents/Conventions/DocumentConventions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ export class DocumentConventions {
return this._dateUtil;
}

public set dateUtil(value: DateUtil) {
this._assertNotFrozen();
this._dateUtil = value;
}

public get readBalanceBehavior(): ReadBalanceBehavior {
return this._readBalanceBehavior;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Utility/DateUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DateUtil {

public static utc: DateUtil = new DateUtil({ useUtcDates: true });

public constructor(private _opts: DateUtilOpts) {}
public constructor(protected opts: DateUtilOpts) {}

public static timestamp(): number {
return moment().unix();
Expand All @@ -35,7 +35,7 @@ export class DateUtil {
}

let parsed;
if (this._opts.useUtcDates || this._opts.withTimezone || dateString.endsWith("Z")) {
if (this.opts.useUtcDates || this.opts.withTimezone || dateString.endsWith("Z")) {
parsed = moment.parseZone(dateString, DateUtil.DEFAULT_DATE_TZ_FORMAT);
} else {
parsed = moment(dateString, DateUtil.DEFAULT_DATE_FORMAT);
Expand All @@ -50,15 +50,15 @@ export class DateUtil {

public stringify(date: Date): string {
const m = moment(date);
if (this._opts.useUtcDates) {
if (this.opts.useUtcDates) {
m.utc();
}

const format = this._opts.withTimezone
const format = this.opts.withTimezone
? DateUtil.DEFAULT_DATE_TZ_FORMAT
: DateUtil.DEFAULT_DATE_FORMAT;
const result = m.format(format);
if (this._opts.useUtcDates && !this._opts.withTimezone) {
if (this.opts.useUtcDates && !this.opts.withTimezone) {
return result + "Z";
}

Expand Down

0 comments on commit fc5e149

Please sign in to comment.