How to use the luxon.DateTime function in luxon

To help you get started, we’ve selected a few luxon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Novaleaf / xlib / src / _obsolete / cache.ts View on Github external
function returnOrClone( potentialValue: TValue ): TValue {
            let toReturn: TValue;
            if ( options.noClone ) {
                //use newValue directly
                toReturn = potentialValue;
            } else if ( options.shallowClone === true ) {
                toReturn = _.clone( potentialValue );
            } else {
                toReturn = _.cloneDeep( potentialValue );
            }
            return toReturn;
        }

        let now = luxon.DateTime.utc();
        if ( options.fetchExpiresDuration.valueOf() <= 0 ) {
            throw new diagnostics.XlibException( "Cache: item to insert is alreadey expired (fetchExpiresAmount less than or equal to zero)" );
        }
        // do a garbage collection pass (one item checked per read call) 
        this._tryGCOne( now );


        let cacheItem = this._storage[ key ];
        if ( cacheItem == null ) {
            cacheItem = {
                value: undefined,
                currentFetch: null,
                expires: luxon.DateTime.fromMillis( 0 ),
                gcAfter: now.plus( luxon.Duration.fromObject( { seconds: options.fetchExpiresDuration.as( "seconds" ) * options.gcAfterMultipler } ) ) //now.plus( fetchExpiresDuration.asSeconds() * options.gcAfterMultipler, "seconds" ),
            };
            this._storage[ key ] = cacheItem;
github Novaleaf / xlib / src / core / lolo.ts View on Github external
import { jsonX } from "./serialization";
export { jsonX };


import * as luxon from "luxon";
/** Time: return time in utc.  pass no arguments to get the current time.
	*
	* Shortcut to ```xlib.time.luxon.DateTime.utc()```
	* @example
const start = __.utc();
//....do stuff...
const elapsed = start.until( __.utc() ).length( "millisecond" );
*/
// tslint:disable-next-line: no-unbound-method
export const utc = luxon.DateTime.utc;
/** Time:  create a duration object.
	*
	* Shortcut to ```xlib.time.Duration.fromObject()```
	* @example
	const oneHundredMs = __.duration( { milliseconds: 100 } );
  */
// tslint:disable-next-line: no-unbound-method
export const duration = luxon.Duration.fromObject;


import { bluebird } from "./promise";
/** the ```bluebird``` library with some helpers injected , and rejection reasons restricted to Error
	*
	* shortcut to ```xlib.promise.bluebird```
	* @example
	const results = await __.bb.resolve(someObject.someAsyncFcn()).timeout(1000,"waited too long");
github nib-health-funds / hammertime / src / tags / cantTouchThisBetween.js View on Github external
module.exports = (tag) => {
  if (!caseInvariantStringEquals(tag.Key, 'hammertime:cantTouchThisBetween')) {
    return false;
  }

  if (CANT_TOUCH_THIS_BETWEEN_REGEX.test(tag.Value)) {
    const matches = CANT_TOUCH_THIS_BETWEEN_REGEX.exec(tag.Value);
    const now = luxon.DateTime.utc();
    const start = luxon.DateTime.fromISO(matches[1]);
    const end = luxon.DateTime.fromISO(matches[2]);

    if (!start.isValid) {
      console.log('Start date was not in the correct format');
      return false;
    }

    if (!end.isValid) {
      console.log('End date was not in the correct format');
      return false;
    }

    return now <= end && now >= start;
  }

  return false;
github nib-health-funds / hammertime / src / tags / cantTouchThisBefore.js View on Github external
module.exports = (tag) => {
  if (!caseInvariantStringEquals(tag.Key, 'hammertime:cantTouchThisBefore')) {
    return false;
  }

  const end = luxon.DateTime.fromISO(tag.Value);

  if (end.isValid) {
    return luxon.DateTime.utc() < end;
  }

  console.log('End date was not in the correct format');

  return false;
};
github valor-software / ng2-charts / src / app / financial-chart / financial-chart.component.ts View on Github external
getRandomData(dateStr: string, count: number) {
    let date = luxon.DateTime.fromRFC2822(dateStr);
    const data = [this.randomBar(date, 30)];
    while (data.length < count) {
      date = date.plus({ days: 1 });
      if (date.weekday <= 5) {
        data.push(this.randomBar(date, data[data.length - 1].c));
      }
    }
    return data;
  }
github lonekorean / wordpress-export-to-markdown / index.js View on Github external
function getPostDir(post) {
	let dir = argv.output;
	let dt = luxon.DateTime.fromISO(post.frontmatter.date);

	if (argv.yearmonthfolders) {
		dir = path.join(dir, dt.toFormat('yyyy'), dt.toFormat('LL'));
	} else if (argv.yearfolders) {
		dir = path.join(dir, dt.toFormat('yyyy'));
	}

	if (argv.postfolders) {
		let folder = post.meta.slug;
		if (argv.prefixdate) {
			folder = dt.toFormat('yyyy-LL-dd') + '-' + folder;
		}
		dir = path.join(dir, folder);
	}

	return dir;
github linkfy / Tools-for-Instagram / node_modules / instagram-private-api / dist / repositories / media.repository.js View on Github external
async configure(options) {
        const devicePayload = this.client.state.devicePayload;
        const now = luxon_1.DateTime.local().toFormat('yyyy:mm:dd HH:mm:ss');
        const width = options.width || 1520;
        const height = options.height || 2048;
        const form = this.applyConfigureDefaults(options, {
            width,
            height,
            upload_id: Date.now().toString(),
            timezone_offset: this.client.state.timezoneOffset,
            date_time_original: now,
            date_time_digitalized: now,
            caption: '',
            source_type: '4',
            media_folder: 'Camera',
            edits: {
                crop_original_size: [width, height],
                crop_center: [0.0, -0.0],
                crop_zoom: 1.0,
github nib-health-funds / hammertime / events.js View on Github external
function getCronDayHour(day = '0', hour, zone) {
  return {
    day: luxon.DateTime.fromObject({ weekday: day, hour, zone }).setZone('UTC').weekdayShort,
    hour: luxon.DateTime.fromObject({ weekday: day, hour, zone }).setZone('UTC').hour,
  };
}
github openequella / openEQUELLA / Source / Plugins / Core / com.equella.core / js / src / Utils / Dates.js View on Github external
exports._dateToLuxon = function (o) {
    return Luxon.DateTime.local(o.y, o.m, o.d);
}