import { Component } from '@angular/core';
import * as moment from 'jalali-moment';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
selectedFormat = "jDD-jMM-jYYYY";
inputFormat = "jDD-jMM-jYYYY";
outputFormat = "DD-MM-YYYY";
momentInput = "13-5-1395";
birthDayInput = "1367/11/4";
describeToday() {
return moment().format('[today in jalalian system is ]jYYYY/jM/jD [and in gregorian system is ] YYYY/M/D')
}
getTodayFormatted(){
return moment().format(this.selectedFormat);
}
getInputFormatted(){
return moment(this.momentInput, this.inputFormat).format(this.outputFormat);
}
getDayFeatures(){
let commands=[];
const m = moment(this.birthDayInput, 'jYYYY/jM/jD');
commands.push(
{com:"const m = moment('"+this.birthDayInput+"', 'jYYYY/jM/jD')"},
{com:"m.format('jYYYY/jM/jD [is] YYYY/M/D');", res: m.format('jYYYY/jM/jD [is] YYYY/M/D')},
{com:"m.format('jYYYY');", res: "year : " + m.format('jYYYY')},
{com:"m.format('jYYYY');", res: "miladi : " + m.format('YYYY')},
{com:"m.format('jMM');", res: "month : " + m.format('jMM')},
{com:"m.format('jMMMM');", res: "fa month : " + m.locale('fa').format('jMMMM')},
{com:"m.format('jD');", res: "day of month : " + m.format('jD')},
{com:"m.format('jDDD');", res: "day of year : " + m.format('jDDD')},
{com:"m.jWeek();", res: m.jWeek()+"th week in year"},
{com:"m.jDaysInMonth();", res: m.jDaysInMonth()},
{com:"m.jIsLeapYear();", res: m.jIsLeapYear()},
{com:"m.format('ddd');", res: m.format('ddd') },
{com:"m.format('dd');", res: m.format('dd') },
{com:"m.format('d') + ' shanbe';", res: m.format('d') + ' shanbe' },
);
return commands;
}
howToChangeDate(){
let logs=[];
const m = moment(this.birthDayInput, 'jYYYY/jM/jD');
logs.push(
{com:"const m = moment('1367/11/4', 'jYYYY/jM/jD')"},
{com:"m.add(1, 'jYear')", temp:m.add(1, 'jYear')},
{com:"m.add(1, 'jMonth')", temp:m.add(2, 'jMonth')},
{com:"m.add(2, 'day')", temp:m.add(3, 'day')},
{com:"m.format('jYYYY/jM/jD');" ,res: m.format('jYYYY/jM/jD')},
{com:"m.jMonth(11)", temp:m.jMonth(11)},
{com:"m.startOf('jMonth')", temp:m.startOf('jMonth')},
{com:"m.format('jYYYY/jM/jD')", res: m.format('jYYYY/jM/jD')},
{com:"m.jYear(1392)", temp:m.jYear(1392)},
{com:"m.startOf('jYear')", temp:m.startOf('jYear')},
{com:"m.format('jYYYY/jM/jD')", res: m.format('jYYYY/jM/jD')},
);
return logs;
}
}
// The browser platform with a compiler
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// The app module
import { AppModule } from './app.module';
// Compile and launch the module
platformBrowserDynamic().bootstrapModule(AppModule);
p,input,select{
border:none;
border-bottom:2px solid red;
text-align:center;
background:white;
outline:0;
}
code, strong{
color:#333;
}
<!DOCTYPE html>
<html>
<head>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<title>Jalali Moment</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.25?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err) {
console.error(err);
});
</script>
</head>
<body class="container">
<my-app>Loading...</my-app>
</body>
</html>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
/**
* PLUNKER VERSION
* (based on systemjs.config.js in angular.io)
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'ts': 'npm:plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'npm:typescript@2.2.2/lib/typescript.js',
'ngx-window-token':'npm:ngx-window-token@0.0.2',
'jalali-moment': 'npm:jalali-moment/dist/jalali-moment.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
# [jalali-moment](https://github.com/fingerpich/jalali-moment) demo typescript
Display, parse, manipulate, convert jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times.
تبدیل تاریخ شمسی به میلادی و بر عکس
- [نصب این کتابخانه](https://github.com/fingerpich/jalali-moment#install)
- [استفاده از تاریخ شمسی در node js](https://github.com/fingerpich/jalali-moment#using-in-nodejs)
- [استفاده از تاریخ شمسی در browser](https://github.com/fingerpich/jalali-moment#using-in-browser)
- [استفاده از سیستم جلالی در تایپ اسکریپت](https://github.com/fingerpich/jalali-moment#typescript)
- [استفاده از سیستم تاریخ شمسی در جاواسکریپت](https://github.com/fingerpich/jalali-moment#es5)
- [توابع موجود در کتابخانه برای مدیریت تاریخ شمسی](https://github.com/fingerpich/jalali-moment#api)
- [گرفتن تاریخ از یک رشته](https://github.com/fingerpich/jalali-moment#parse)
- [نمابش تاریخ با سیستم (جلالی شمسی خورشیدی ) و یا میلادی](https://github.com/fingerpich/jalali-moment#display-jalali-or-miladi-date)
- [تغییر تاریخ شمسی](https://github.com/fingerpich/jalali-moment#manipulate)
- [بررسی تاریخ جلالی (شمسی خورشیدی](https://github.com/fingerpich/jalali-moment#validate)
- [تبدیل تاریخ میلادی به تاریخ جلالی (شمسی خورشیدی](https://github.com/fingerpich/jalali-moment#convert-gregorian-miladi-to-jalali-shamsi-persian)
- [تبدیل تاریخ جلالی (شمسی خورشیدی) به میلادی](https://github.com/fingerpich/jalali-moment#convert-persianjalali--shamsi-khorshidi-to-gregorian-miladi-calendar-system)
- [نمایش تاریخ به زبان فارسی](https://github.com/fingerpich/jalali-moment/)
- [استفاده از سیستم تاریخ جلالی (شمسی یا خورشیدی) به عنوان سیستم اصلی برای کتابخانه](https://github.com/fingerpich/jalali-moment/)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
/* App Root */
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
<br>
<div>{{describeToday()}} </div>
<br>
<div>
<h4>Date Formating</h4>
<code>moment().format(</code>
<select [(ngModel)]="selectedFormat">
<option>jM</option>
<option>jYYYY</option>
<option>jD</option>
<option>jMM</option>
<option>jYY</option>
<option>jMMMM</option>
<option>jD</option>
<option>jDD</option>
<option>jd</option>
<option>jddd</option>
<option>jDD-jMM</option>
<option>jDD-jMM-jYYYY</option>
</select>
<code>);</code><strong>{{getTodayFormatted()}}</strong>
</div>
<br>
<div>
<h4>Set a custom date and format it</h4>
<code>moment(</code>
<input type="text" [(ngModel)]="momentInput">
<code>,</code>
<select [(ngModel)]="inputFormat">
<option>DD-MM-YYYY</option>
<option>jDD-jMM-jYYYY</option>
</select>
<code>).format(</code>
<select [(ngModel)]="outputFormat">
<option>DD-MM-YYYY</option>
<option>jDD-jMM-jYYYY</option>
</select>
<code>);</code> <strong>{{getInputFormatted()}}</strong>
</div>
<br>
<br>
<div>
<h4>How to extract a jalali day features</h4>
<input type="text" [(ngModel)]="birthDayInput">
<div *ngFor="let command of getDayFeatures()">
<code>{{command.com}}</code>
<strong>{{command.res}}</strong>
</div>
</div>
<br>
<br>
<div>
<h4>How to change a date</h4>
<div *ngFor="let tip of howToChangeDate()">
<code>{{tip.com}}</code>
<strong>{{tip.res}}</strong>
</div>
</div>